I have the following code:
import os, fcntl
f = open('./testfile.t', 'wb')
f.write(os.urandom(64))
fcntl.flock(f.fileno(), fcntl.LOCK_EX)
print 'Locked'
try:
f2 = open('./testfile.t', 'wb')
except IOError as err:
print err.errno
print err
The idea is that second open
should return an error, because file is still locked.
The problem is it doesn't.
Moreover, if I try to acquire a lock on f2.fileno()
this code just hangs up, instead of throwing an exception.
What do I do wrong?