A lock that times out but doesn't poll

Antoon Pardon apardon at forel.vub.ac.be
Fri Nov 26 04:27:48 EST 2004


Op 2004-11-25, Jive schreef <someone at microsoft.com>:
> I just took a look at Timer in threading.py.  Correct me if I'm wrong, but
> it appears that the
> timer always stays around for the programmed interval, even if cancel() is
> called on it.  If that's the
> case, it's hard for me to see how it could be used to implement a useful
> timed lock.  The typical scenario
> is for a thread to obtain a lock fairly quickly when things are functioning
> properly, but to wait on it with
> a long timeout in case some resource dries up -- like a socket connection
> breaks.  In that scenario,
> a thread that repeatedly waits on a timed lock will generate new Timer
> threads faster than they will die off.

Only at the beginning, after the mean timeout Timer threads should die
out as fast as new are created. But that may be too much.

But is is worst. I found out that in order to wait the specific time
the Timer class uses a polling loop until the specified time is expired.

-- 
Antoon Pardon



More information about the Python-list mailing list