maemo.org Bugzilla – Bug 7809
Python widgets can't use threads
Last modified: 2010-01-22 20:49:54 UTC
You need to
before you can comment on or make changes to this bug.
EXACT STEPS LEADING TO PROBLEM:
Python developers had taken care about low qualified programmers and
implemented their python threads in a non standard manier. They decided, that
making explicit synchronization is good, but that doesn't work with GTK.
I'm writing a widget, which needs about 15 seconds to react to a user because
of network delays. Making query in main thread make hildon-home to hung for
these 15 seconds. The solution is obvilous: use threads.
1) Make a GTK python application (In my case the application is hildon-home, so
that's why I'm writing here).
2) Create a thread (for example from a widget).
Thread should be run in parallel
Thread is suspended as soon, as function, from which it was created finishes.
It may be resumed later, for example if I run time.sleep() from main thread.
But as far, as I don't need to run sleep, it would be suspended forever.
The solution is easy: run gtk.gdk.threads_init()
This will fix deadlocking of GTK and threads and widget would run as intended.
But this function MUST be run before gtk.main(), so I can't run it from my
widget. So please either add invocation of gtk.gdk.threads_init() to
hildon-home to allow python widgets make threads and make interface more
responsive or add to somewhere to documentation that python widgets can't make
long calculations due to bad design of python threads.
P.S. Right now I think I should reimplement my widget in C++.
Other solution: don't use threads (they are badly broken in Python running with
PyGTK anyway), but use gobject IO callbacks.
So why is this a Maemo Desktop platform issue and not filed under PyGtk?
And what is the exact request to change here?
(In reply to comment #2)
> So why is this a Maemo Desktop platform issue and not filed under PyGtk?
> And what is the exact request to change here?
This bug is filled here because it can be fixed only in hildon-home or you can
decide not to fix it at all.
Design of python (so it is won't fix there) is so, that threads in widgets
would only work if hildon-home before calling gtk.main() would call
gtk.gdk.threads_init(). I don't know if it is possible.
If you find, that such fix is not suitable because it's ugly, then this issue
should be addressed to PyGTK with request to add to documentation warning, that
threads are not supported for widgets by design and developers should consider
using other languages for developing widgets, which need parallelism.
(In reply to comment #1)
> Other solution: don't use threads (they are badly broken in Python running with
> PyGTK anyway), but use gobject IO callbacks.
I agree. IO callbacks are better solution in this case and can be used to write
any parallel code (with some loss of efficiency). But if you want speed python
(as any script language) is not the language you want to use.