Gentoo Forums
Gentoo Forums
Quick Search: in
Threads and UI responsiveness in wxpython
View unanswered posts
View posts from last 24 hours

rackathon
 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
nyk
Guru
Guru


Joined: 27 Aug 2004
Posts: 518
Location: Bern (Switzerland)

PostPosted: Sat Apr 01, 2006 7:23 pm    Post subject: Threads and UI responsiveness in wxpython Reply with quote

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
View user's profile Send private message
nyk
Guru
Guru


Joined: 27 Aug 2004
Posts: 518
Location: Bern (Switzerland)

PostPosted: Thu Apr 06, 2006 7:27 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum