29 lines
519 B
Python
29 lines
519 B
Python
|
#!/usr/bin/python3
|
||
|
|
||
|
import sys, time, fcntl, os
|
||
|
|
||
|
clientId = sys.argv[1]
|
||
|
message = sys.argv[2]
|
||
|
|
||
|
clientFilePath = f'users/{clientId}.txt'
|
||
|
|
||
|
def write(s):
|
||
|
f = open(clientFilePath, 'w+')
|
||
|
try:
|
||
|
fcntl.flock(f, fcntl.LOCK_EX)
|
||
|
if f.read() == '':
|
||
|
f.write(s)
|
||
|
else:
|
||
|
f.close()
|
||
|
time.sleep(1)
|
||
|
write(s)
|
||
|
except Exception as e:
|
||
|
print(e)
|
||
|
f.close()
|
||
|
|
||
|
for i in range(10):
|
||
|
write(f'{i}: {message}')
|
||
|
time.sleep(2)
|
||
|
|
||
|
os.remove(clientFilePath)
|