Premature wakeup of time.sleep()
Erich Schreiber
gmane-esc at mmf.at
Mon Sep 12 07:39:35 EDT 2005
In the Python Library Reference the explanation of the time.sleep()
function reads amongst others:
> The actual suspension time may be less than that requested because
> any caught signal will terminate the sleep() following execution
> of that signal's catching routine. Also, the suspension time may
> be longer than requested by an arbitrary amount because of the
> scheduling of other activity in the system.
I don't understand the first part of this passage with the premature
wakeup. What signals would that be?
I've written a script that tries to bench the responsiveness of a
virtual Linux server. My script sleeps for a random time and on waking
up calculates the difference of the proposed and actual wakeup time.
The essential code fragment is
while True:
ts = tDelay()
t1 = time.time()
time.sleep(ts)
t2 = time.time()
twu = str(datetime.datetime.utcfromtimestamp(t1 + ts))
logResults(LOGFILE, twu, ts, int((t2-t1-ts)*1000))
Whereas tDelay() returns a (logarithmically) randomly distributed real
number in the range [0.01, 1200] which causes the process to sleep
from 10 ms to 20 minutes.
In the logs I see a about 1% of the wake-up delays beeing negative
from -1ms to about -20ms somewhat correlated with the duration of the
sleep. 20 minute sleeps tend to wake-up earlier then sub-second
sleeps. Can somebody explain this to me?
Regards,
Erich Schreiber
More information about the Python-list
mailing list