| View previous topic :: View next topic |
| Author |
Message |
nyk Guru


Joined: 27 Aug 2004 Posts: 518 Location: Bern (Switzerland)
|
Posted: Sat Apr 01, 2006 7:23 pm Post subject: Threads and UI responsiveness in wxpython |
|
|
| I'm writing a wxpython prog that spawns a long computation in a C module (wrapped by swig) as a thread. But when I start the thread, the UI is not responsive anymore. What could have gone wrong? The command after starting the thread in the Event-Handler of the Button for starting the thread does not get executed (statusbar text). Does anyone have a hint? |
|
| Back to top |
|
 |
nyk Guru


Joined: 27 Aug 2004 Posts: 518 Location: Bern (Switzerland)
|
Posted: Thu Apr 06, 2006 7:27 am Post subject: |
|
|
The solution was to include | Code: | | #include <Python.h> | in my C module and then put the main computation loop inside a | Code: |
Py_BEGIN_ALLOW_THREADS
...(computation)...
Py_END_ALLOW_THREADS |
Now it works to run that computation thread in the background and have an active GUI during that time!
The "Py_BEGIN_ALLOW_THREADS" creates a python thread-control object for the C module and releases the GIL, so it can work in parallel with other threads.
The only problem now is that the progress bar sometimes doesn't get updated, but the same data in the status bar gets displayed. So probably the computation thread is not "nice" enough, takes away all CPU cycles. Can this be influenced somehow? |
|
| Back to top |
|
 |
|