time.sleep(1) sometimes runs for 200 seconds under windows

Magnus Lycka lycka at carmen.se
Wed Mar 1 11:57:59 CET 2006

Mladen Adamovic wrote:
> Magnus Lycka wrote:
>> On Windows that it. At least on Linux and Solaris, time.clock() returns
>> CPU time. If time.clock() returns significantly different values before
>> and after time.sleep(1), there's something seriously broken in sleep on
>> such platforms.
> No!

It seems I can't say anything in this thread without getting 
contradicted! :)

I'm sorry if I wasn't clear in explaining the concept of CPU
time in Unix (and other multi user operating systems). This is
an entity that is registered per process. Roughly, the code below
means that calling f(arg) used s CPU seconds *in* *this* *process*.

c0 = time.clock()
s = time.clock() - c0

If f is time.sleep, s should be 0, or at least very close to 0
on systems such as Linux where time.clock() measures CPU time.
Otherwise something is broken. (On Linux, where CPU time has a
low resolution (100 ms?) I've never seen any other figure than
0.0.) There will obviously be other processes using the CPU while
this process is sleeping, but this process should use no CPU time.

Wall time delays will obviously depend on the load of the machines
in question. I rarely see > 1 ms on Linux boxes with a low load.
With a higher load, or many users, I see delays of up to 10 ms or
so now and then, but rarely more.

I suspect that observations from Java might not be completely
relevant for Python. I suspect the Java implementation might add
additional delays.

More information about the Python-list mailing list