How to pause within a thread

Peter Hansen peter at engcorp.com
Fri Jun 13 07:16:35 EDT 2003


Rolf Wester wrote:
> 
> I have a thread that is polling a server for completion of a routine.
> This thread should only consume little cpu time so I want to pause this
> thread between calls to the server. Is there any simple function for
> this or do I have to use a Timer object?

import time
time.sleep(x)  where x is a float, in seconds

But this is probably not the best approach.  Rather than
"poll" the server, presumably using a non-blocking recv() call (?)
you should investigate the select.select() function.  Either
that, or base your code on an existing framework that already
deals with such issues in simpler and more scalable ways
(e.g. asyncore, or Twisted).

-Peter




More information about the Python-list mailing list