[Tutor] fcntl: Blocking or non-blocking

Sheila King sheila@thinkspot.net
Tue, 28 Aug 2001 22:32:33 -0700

OK, I've been pestering the python-list/comp.lang.python with my
questions about file locking, and now that I'm down to some more
elementary concepts (that illustrate my fundamental cluelessness with
*nix systems), I've decided to give them a break and pester you
kind-hearted and patient folks. ;)

Here's the deal:
I'm writing a module that will perform file locking. I want it to work
on both Windows and Unix. This requires platform specific stuff, so I
write two separate modules, and then wrap them in one cross-platform
module with a common interface.

OK, I've got that all down, now, I think.
But one question remains:

On Unix I have a choice of using blocking or non-blocking calls to fcntl
to get the file lock.

Blocking obviously saves me the effort of having to code retries (which
I have to do for the Windows version, anyhow).

But I have a concern: what if I try for a blocking call, and the process
never acquires the lock? (Maybe I should specify, that these are for CGI
scripts, anyhow. So, I guess eventually the process will time out and
die.) Should I just code the blocking calls? Or should I code
non-blocking and have retries with sleep in there? I can't see any easy
way in Python to use the fcntl.lockf command and get a blocking call to
time out.

Anyone interested in the 50+ messages on this topic in comp.lang.python,
can look at the two threads that start with these messages:



Sheila King