[Tutor] how do I post event to thread?

Jeff Peery jeffpeery at yahoo.com
Thu Aug 27 03:38:58 CEST 2009


hello,
I've read a bit about multi thread communication, and found that most people use a queue, which makes sense. however in my case I simply have two threads, a main thread and one other. the main thread is doing many different things and the second thread is receiving numerical data via a serial port.. when data comes in, I want to post the data to the main thread so it can use the it. I don't want to use a queue because I don't want to lock up my main thread in a loop that is always looking at the queue waiting to get something out of it. I would prefer to do something like post an event. The alternative would be to simply have a method in my main thread called OnResult(data), and when data comes in to the second thread I could call main_thread.OnResult(data). This would solve my problem, but I'm not sure if that is an ok thing to do... calling a main thread method from within a second thread?
 
is there a way to post an event to the main thread from a second thread?
 
Is it ok to pass the main thread (self) into the second thread and have the second thread
call a main_thread.OnResult(data) method to pass the data into the main thread? I'm not sure how the main thread handles this, my guess is that it can only do one thing at a time so it might be exactly that same as 'posting an event'.
 
any thoughts would be much appreciated. thanks!
 
Jeff


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090826/a920a003/attachment-0001.htm>


More information about the Tutor mailing list