views:

106

answers:

2

If multiple events are posted using wxPostEvent/wxCallAfter from same thread e.g. on button click are they supposed to be processed in same order?

In the below example wx.Callafter is used to post events, which eventually will call the callback functions, will they be called in same order, in which they were passed to wx.CallAfter

def onbutton(self, event):
    wx.CallAfter(func1)
    # some more code
    wx.CallAfter(func2)
A: 

I believe it should be guaranteed. I have some code that grabs data from the serial port in a thread and fires off events for wx to handle. Even when receiving data at 115kbps--where it would undoubtedly fire off several events before they are processed--the data shows up in order when wx calls my handler to print/log out the data.

Nick T
A: 

CallAfter posts the events to the event queue and these should be processed in order. Still, they are processed on idle events, not based on function completion, so the func2 to could be processed before func1 is done depending on the timing of idle events (e.g. wx.Yield, etc.) There's a discussion about an issue with this here, and it seems that it can be sort-of tricky.

tom10
I also posted same question to wxpython mailing list, Robin has a good answer http://groups.google.com/group/wxpython-users/browse_thread/thread/67d059c3f984b87f#
Anurag Uniyal
Yes, Robin's is a good answer. Still, it's worth looking at this part of the thread I referred to: http://aspn.activestate.com/ASPN/Mail/Message/wxpython-users/3483407 . Here, it isn't the just the obvious Yield statement, or less obvious model dialog, but also a paint event because that is queued out of order.
tom10