How to pause within a thread

Rolf Wester wester at ilt.fhg.de
Fri Jun 13 09:30:05 EDT 2003


Peter Hansen wrote:
> 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
> 
Thank you very much. That's exactly what I was looking for.

> 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).
> 

I think I didn't describe correctly what I'm doing. I have a server 
written in Python which starts another process (a C++ program). This 
process takes some time to complete and I want to periodically ask the 
server whether the process has finished. Meanwhile I want to make other
computations on the client side (Python with C-extensions) and 
communicate with the server.

Thanks again

Rolf Wester





More information about the Python-list mailing list