Your problem is that open(...,'w') is not locked. Use something like: lockf = open('aaa', 'a') fnctl.flock(lockf,fnctl.LOCK_EX) file = open('aaa', 'w') file.write('asdf') file.close() lockf.close()
[EMAIL PROTECTED] wrote:
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()
-- http://mail.python.org/mailman/listinfo/python-list