thread question

Syver Enstad syver at inout.no
Mon Sep 22 05:51:46 EDT 2003


Rolf Wester <wester at ilt.fraunhofer.de> writes:

> Hi,
> 
> I have an application that starts a second thread, that receives
> messages via a socket-server and puts that messages into a queue. The
> main thread is polling that queue for new messages. My problem is that
> the main thread takes to much of the time polling the empty queue
> while the socket-server thread doesn't get enough time for receiving
> the messages. Is it possible to force the main threat to sleep for a
> certain
> amount of time or give the socket-server thread a higher priority?
> Thanks in advance.

The good answer to your question:
Use a Queue.Queue instance as your queue. The queue instance has
methods that block if the queue is empty.

The direct answer to your question:
import time
time.sleep(5) # sleeps 5 seconds





More information about the Python-list mailing list