flock seems very unsafe, python fcntl bug?

xucs007 at gmail.com xucs007 at gmail.com
Sat Jun 21 19:54:03 EDT 2008


I ran following 2 programs (lock1, lock2) at almost same time,
to write either "123456", or "222" to file "aaa" at the same time.
But I often just got "222456" in "aaa" .

Is this a bug of python fcntl module ? See 2 programs I ran:



#!/usr/bin/env python
import fcntl, time
file = open('aaa', "w")
fcntl.flock(file, fcntl.LOCK_EX)
file.write('123456')
time.sleep(10)
file.close()


#!/usr/bin/env python
import fcntl, time
file = open('aaa', "w")
fcntl.flock(file, fcntl.LOCK_EX)
file.write('222')
time.sleep(10)
file.close()



More information about the Python-list mailing list