Benjamin Loison
03c2566a20
While previous implementation was able to send two independent messages, now we can send an arbitrary amount of independent messages.
29 lines
519 B
Python
Executable File
29 lines
519 B
Python
Executable File
#!/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)
|