with timeout(1):
    f = open('test.lck', 'w')
try:
    fcntl.flock(f.fileno(), fcntl.LOCK_EX)
except IOError as e:
    if e.errno != errno.EINTR:
        raise e
print('Lock timed out')
fcntl.flock - how to implement a timeout?