Hello all,
My platform is Solaris 10 (x86), Python 2.4.3, and wxPython 2.6.3.3.
I’m using wx.CallAfter from a python sub-thread to make a call back to the main thread, always to the same method. For the most part this works very nicely. However today I discovered odd behavior in a case where the sub-thread makes two rapid successive
wx.CallAfters to the same ‘mainThreadMethod’. It is confusing to explain. To help illustrate, what I see are the following actions in the following relative time sequence.
Thread 5 waits for input, gets msgA, then calls
wx.CallAfter(mainThreadMethod, msgA)
Thread 5 again waits for input, immediately gets msgB, then calls
wx.CallAfter(mainThreadMethod, msgB)
Then in the main thread,
Enter --> mainThreadMethod(msgA)
Enter --> mainThreadMethod(msgB)
Return from <-- mainThreadMethod(msgB)
Return from <-- mainThreadMethod(msgA)
It is a bit confusing to me how this can happen. What I am expecting (and see most of the time) is:
Enter --> mainThreadMethod(msgA)
Return from <-- mainThreadMethod(msgA)
Enter --> mainThreadMethod(msgB)
Return from <-- mainThreadMethod(msgB)
The odd behavior seems to occur when there is more GUI activity within mainThreadMethod, such as displaying an image and updating alot of widgets.
I tried to serialize the calls with python locks as well as the python mutex class, so far without success. However, I don’t yet fully understand these mechanisms in python, and may not be using them correctly.
So, …
Is this correct wx.CallAfter behavior?
Is there a way to guarantee that the methods passed in wx.CallAfter are executed in the main thread serially, so that each instance of each call starts and finishes before the next?
Thanks in advance for any help or suggestions.
- Chris Botos