file - python fcntl does not lock as expected (2) -


i'd use lock_ex prevent other processes modify file under modification.

process a:

from fcntl import flock, lock_ex, lock_nb time import sleep f=open("tmp.txt", "w") flock(f.fileno(), lock_ex|lock_nb) f.write("xxxx") f.flush() sleep(20) f.close() 

5 seconds after starts, process b:

f=open("tmp.txt", "w") f.close() 

and "tmp.txt" emptied process b... no ioerror raised in process b. how can 1 prevent "tmp.txt" modified 2 processes using exclusive access ?

note: "innocent" process b not use flock(), fopen() create new file. what's use of exclusive lock on file if else can modify file ? of course, if b uses flock() well, raises ioerror, if not ???

by default, flock advisory locking mechanism. more details, see this question.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -