Created
May 19, 2023 13:14
-
-
Save strboul/57559a39e040fdc16fcfc4cd0d50c1a6 to your computer and use it in GitHub Desktop.
lsof test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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