andrea crotti
2012-10-18 13:14:02 UTC
I'm trying to understand how I can lock a file while writing on it,
because I might have multiple processes working on it at the same time.
I found the fcntl.lockf function but if I do this:
In [109]: locked = open('locked.txt', 'w')
In [110]: fcntl.lockf(locked, fcntl.LOCK_EX)
I can happily open the file with vim from somewhere and write on it, so
it doesn't seem to be very useful, or am I missing something?
I can otherwise use the classic ".lock" file when working on it, but I
would be glad to see a smarter solution (should only work on Linux)..
because I might have multiple processes working on it at the same time.
I found the fcntl.lockf function but if I do this:
In [109]: locked = open('locked.txt', 'w')
In [110]: fcntl.lockf(locked, fcntl.LOCK_EX)
I can happily open the file with vim from somewhere and write on it, so
it doesn't seem to be very useful, or am I missing something?
I can otherwise use the classic ".lock" file when working on it, but I
would be glad to see a smarter solution (should only work on Linux)..