I tried to move some heavy calulations to a separate thread as dfemonstrated on
the LongRunningTasks wiki page. I did that by passing a reference to the method
which does the calculation to the Thread class on creation and have it called
from the Thread's run method. Is that allowed when threading?
Presumably you mean that you used...
x = threading.Thread(target=obj.method, args=...)
x.start()
or some variant thereof. Yes, that should work just fine. You may need
to use Queue, wx.CallAfter or wx.FutureCall to get the result back to
the GUI thread, but it should work. If you want to try something else,
there is also wx.lib.DelayedResult, which was designed with this kind of
thing in mind.
I noticed strange
behaviour of the application, e.g. window repainting is delayed/lost even after
the calculation thread has finished, the application sometimes completely
crashes with a X error (Xlib: unexpected async reply (sequence 0x8ff34)!) and
the caluclation seems to run much slower in its own thread.
Show the code that you are using to create the thread. I suspect that
you may not be creating another thread. Because of the way Python
threading works, while you have two threads running (the main GUI thread
and your worker thread), both will necessarily run slower than if you
were only running one or the other. Depending on what your worker
thread is doing while your GUI thread is churning along, there is a
chance that you could have issues (I've had issues with wx.FileConfig).
- Josiah
···
Christian <ckkart@hoc.net> wrote: