Skip to content

Instantly share code, notes, and snippets.

@strboul
Created May 19, 2023 13:14
Show Gist options
  • Save strboul/57559a39e040fdc16fcfc4cd0d50c1a6 to your computer and use it in GitHub Desktop.
Save strboul/57559a39e040fdc16fcfc4cd0d50c1a6 to your computer and use it in GitHub Desktop.
lsof test
# Run
# - python test.py
# - lsof test.log
import time
import os
FILE_NAME = "test.log"
def main():
if os.path.exists(FILE_NAME):
os.remove(FILE_NAME)
f = open(FILE_NAME, "a")
counter = 0
while counter < 100:
print(counter)
f.write(f"{counter}\n")
time.sleep(5)
counter += 1
if counter % 5 == 0:
print('flushed')
f.flush()
f.close()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment