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

Magnus Lycka lycka at carmen.se
Fri Feb 24 05:13:50 EST 2006


Paul Probert wrote:
> Yes, I'm doing this:
>           .....
>          oldtime=time.time()
>          time.sleep(1)
>          newtime=time.time()
>          dt=newtime-oldtime
>           if dt > 2:
>               print 'dt=',dt,' time=',time.strftime('%Y_%m_%d_%Hh_%Mm_%Ss')
> Its happening roughly 4 times a day total on our 20 machines, ie about 
> once every 5 days on a given machine.

So, it happens roughly one time out of 400 000 sleeps?

With an operating system such as Windows, this is
probably something you can expect to happen, although
I'm surprised if such long lag times as 200 s are typical.

If you need real time characteristics, you should
probably use a real time operating system, not Windows.

The operating system can schedule jobs as it likes,
and your sleep is obviously just the right time to hand
off the CPU to some other process.

Of course, if something takes 200 seconds, it's typically
because some process is waiting for IO, and if it's waiting
for IO, the CPU should be used by other processes, such as
yours.

Perhaps you can use the event log or some performance
measurement tools to check if something else on the system
happens to coincide with your long delays.



More information about the Python-list mailing list