Re: Premature wakeup of time.sleep()



Erich Schreiber wrote:
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?

That would be signals from the OS, frinstance, if you type ^C into the python console, or kill the process from another command line.



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?



I think the sleep times are quantised to the granularity of the system clock, shich varies from os to os. From memory, windows 95 has a 55mS timer, NT is less (19mS?), Linux and solaris 1mS. All this is from memory, and really comes from discussions I have seen about sleep and time in java, but I am guessing that there are similarities.


Steve
.



Relevant Pages

  • Re: Premature wakeup of time.sleep()
    ... >> The actual suspension time may be less than that requested because ... What signals would that be? ... KeyboardInterrupt exception - and which does interrupt the sleep() ... which is a granularity of 10ms. ...
    (comp.lang.python)
  • Re: Abolishing sleeps in issignal()
    ... mutex complicates sleep queues by forcing them to drop the spinlock to ... check for signals and then check for races. ... So SIGSTOP combined with a stopeventactually breaks because ... debugging events and SIGSTOP not aborting non-restartable syscalls as they ...
    (freebsd-arch)
  • Re: signal to a sleeping process...
    ... in the followin code ..parent forks and sleeps. ... No, signals are asynchronous, and can interrupt normal calls. ... kernel mode to user mode. ... hence according to it..the parent must sleep first and when its state ...
    (comp.unix.programmer)
  • Re: killing thread
    ... Even if I call pthread_cancel or deliver a SIGTERM signal with pthread_kill, the former thread continues to run and it exits only after timer expires. ... So do you really mean that it "continues to sleep", or do you mean that it wakes from the sleep but fails to TERMINATE as you expected? ... The process control signals are an integral part of POSIX/UNIX job control, and changing the semantics from process level to thread level would have broken a lot of things. ... Delivery of the signal, presuming the signal isn't blocked by the target, will interrupt any interruptable call. ...
    (comp.programming.threads)
  • Re: Problems on sleep/resume in XScale and PB 4.2
    ... enters in suspend sequency and when the code of the OEMPowerOff ... function is executed and the PXA255 enters in sleep mode, ... the rest of the signals that reach to the Flash and I am going to try ... like in the first lines of the reset handler in the fwxsc1.s file, ...
    (microsoft.public.windowsce.platbuilder)