[Tutor] fcntl: Blocking or non-blocking

Roeland Rengelink r.b.rigilink@chello.nl
Wed, 29 Aug 2001 08:33:53 +0200


Sheila King wrote:
> 
[snip]
> 
> 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.
> 

It seems to me you answered your own question. If you're worried about
blocking, you better deal with the possibility. Of course you are the
only one who can make the judgement whether the worry is realistic.

I gather you're trying to build a general solution. That's probably good
enough reason to choose non blocking calls, with a mechanism to do
retries until some specified timeout occurs.

Good luck,

Roeland
-- 
r.b.rigilink@chello.nl

"Half of what I say is nonsense. Unfortunately I don't know which half"