Skip to content

Instantly share code, notes, and snippets.

@pelid
Created December 23, 2019 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pelid/3a07309ece6bb5093e6aceb95c50e7c0 to your computer and use it in GitHub Desktop.
Save pelid/3a07309ece6bb5093e6aceb95c50e7c0 to your computer and use it in GitHub Desktop.
Test simultaniously write to file from two scripts

Запустить в одной консоли:

python3 test_write.py A

Во второй консоли:

python3 test_write.py B
import time
import itertools
import sys
prefix = sys.argv[1]
print('Prefix is:', prefix)
with open('test.txt', 'wb') as file:
for index in itertools.count(1):
timestamp = int(time.time())
text_line = f'{prefix}.{index} {timestamp}'
file.write(f'{text_line}\n'.encode('utf-8'))
print(text_line)
file.flush()
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment