confusing thread behavior

paul phartley at gmail.com
Thu Dec 3 16:42:20 EST 2009


I have been experiencing strange thread behavior when I pass a message
received via a Queue to a wx.PostEvent method (from wxPython). The
relevant code in the thread is:

def run(self):
    while self.is_running:
        task = self.queue.get()
        wx.PostEvent(self.app.handle_task, task)

self.queue is a Queue.Queue instance and self.app is a wx.Window
instance

I have a case where two items are placed in the queue one after the
other, and it appears that only the first item is passed to
wx.PostEvent.  If I place a time.sleep(0.1) call anywhere within the
while loop, both items get passed to wx.PostEvent.  It works if I put
time.sleep before the self.queue.get(), in between get() and PostEvent
() or after PostEvent().  So it seems like a short delay is enough to
get two items handled, although it doesn't seem to matter where I
place the delay within the while loop.  Does someone know what might
explain this behavior?  Thanks.



More information about the Python-list mailing list