I was just wondering about the specifics of python's module filelock and its behavior in a few circumstances.
First, how exactly is the with:
statement handled by threads. If multiple threads call with:
is it locked on a thread by thread basis? Is it also possible that two threads could acquire the lock at the same time?
Second, when I use with:
do I have to clear the lock after its use? Is the lock automatically cleared after the with:
statement is done?
Third, I have an instance in my code where I believe a file must be created then locked immediately. Currently I am using this:
channel_file = open(os.path.join('channels', username), 'w+')
with filelock.FileLock(os.path.join('channels', username)):
channel_file.write(json.dumps({'rate': reobj.group(1),'time': reobj.group(2)}))
If there were a possibility that another thread could read the file since the time it was created, would this protect against that?
This also brings up a forth point. Does filelock lock read access while using with:
?