can wxPython be run not in main thread

Hello

I am writing an engineering application where main processing is done in
SWIGged C modules, and the GUI is provided by wxPython. The application
should run both on Windows and Linux and uses OpenGL for 3D rendering.
Currently the GUI is running in the main thread and the computations is
performed in a python thread. Can it be done other way around? In other
words, is it possible to run wxWindows not in the main thread?

Thanks for any suggestions

Marina Gourtovaia

Marina Gourtovaia wrote:

Hello

I am writing an engineering application where main processing is done in
SWIGged C modules, and the GUI is provided by wxPython. The application
should run both on Windows and Linux and uses OpenGL for 3D rendering.
Currently the GUI is running in the main thread and the computations is
performed in a python thread. Can it be done other way around? In other
words, is it possible to run wxWindows not in the main thread?

Sort of, but not quite. wxWindows requires that it be run in the "main thread", but as far as wxPython is concerned, the "main thread" is the first thread to import wxPython. It is possible (though awkward) to arrange it so that wxPython is never imported until the second thread is started, and is only used from within that second thread. It's questionable how much benefit this would give you, though. I've done it once, because I needed a wxPython app to operate as a COM server that could be started programmatically, and there's some threading issues that I never was able to quite resolve (though the app works well enough).

Jeff Shannon
Technician/Programmer
Credit International

Marina Gourtovaia wrote:

Hello

I am writing an engineering application where main processing is done in
SWIGged C modules, and the GUI is provided by wxPython. The application
should run both on Windows and Linux and uses OpenGL for 3D rendering.
Currently the GUI is running in the main thread and the computations is
performed in a python thread. Can it be done other way around? In other
words, is it possible to run wxWindows not in the main thread?

It's possible, but it's tricky. The key is that whatever is the current thread when then the core wxPython extension module is *imported* will be considered by wxPython to be the main GUI thread.

ยทยทยท

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

I am writing an engineering application where main processing is done in
SWIGged C modules, and the GUI is provided by wxPython. The application
should run both on Windows and Linux and uses OpenGL for 3D rendering.
Currently the GUI is running in the main thread and the computations is
performed in a python thread. Can it be done other way around? In other
words, is it possible to run wxWindows not in the main thread?

It's possible, but it's tricky. The key is that whatever is the current thread when then the core wxPython extension module is *imported* will be considered by wxPython to be the main GUI thread.

>It's questionable how much benefit this would give you, though.

Robin and Jef, thanks for your helpful comments. I wonder about benefit as well. Probably will leave it as it is for time being.

Marina Gourtovaia
Research Assiciate
Engineering Design Center
Department of Engineering
University of Cambridge