thread question

R

Rolf Wester

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.

Kind regards

Rolf Wester
 
S

Syver Enstad

Rolf Wester said:
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
 
C

Christoph Becker-Freyseng

Hi,

You can also use threading.Condition()
This is useful for having some max. time and additionaly being able t
start processing earlier again via cond.notify()

Christoph Becker-Freyseng
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top