After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 461551 - gtk.main() hangs if gtk.gdk.threads_init() was called
gtk.main() hangs if gtk.gdk.threads_init() was called
Status: RESOLVED NOTABUG
Product: pygtk
Classification: Bindings
Component: gdk
2.10.x
Other Windows
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2007-07-29 17:23 UTC by techtonik
Modified: 2010-12-23 21:13 UTC
See Also:
GNOME target: ---
GNOME version: 2.9/2.10


Attachments
Broken GTK threading support on win32 (596 bytes, text/plain)
2007-07-29 17:24 UTC, techtonik
Details

Description techtonik 2007-07-29 17:23:14 UTC
pygtk thread support on windows in effectively broken. pygtk applications hang after gtk.gdk.threads_init() is called on Python 2.5.1 

Threads created between gtk.gdk.threads_init() call and gtk.main() call are working and reporting ok, but GUI hangs - only borders are visible, no window background is painted, no response to keyboard/mouse events.

An example workaround described at http://faq.pygtk.org/index.py?req=show&file=faq21.003.htp doesn't work.
Comment 1 techtonik 2007-07-29 17:24:03 UTC
Created attachment 92654 [details]
Broken GTK threading support on win32
Comment 2 Johan (not receiving bugmail) Dahlin 2007-07-29 17:28:35 UTC
You need to call threads_init() before everything else; normally you'd just do

import gobject
gobject.threads_init()
import gtk
...

does that work?
Comment 3 techtonik 2007-07-29 17:34:35 UTC
With gobject it works, but not with gtk.gdk

import gtk.gdk
gtk.gdk.threads_init()
...
Comment 4 Johan (not receiving bugmail) Dahlin 2007-07-29 17:36:47 UTC
You need to call both, it's well known:

  http://faq.pygtk.org/index.py?req=show&file=faq20.001.htp
Comment 5 techtonik 2007-07-29 18:06:37 UTC
The FAQ entry doesn't say about the need to call both. If I call gtk.gdk.threads_init() immediately after gobject.threads_init(), the application hangs again.

import gobject
gobject.threads_init()
import gtk.gdk
gtk.gdk.threads_init()
...


The FAQ entry talks about deprecated gtk.threads_init(), but uses gobject.threads_init() in examples. It also doesn't mention that threads_init() should be called even before other imports. Testcase works ok when I just replace gtk.gdk.threads_init() with gobject.threads_init()
Comment 6 John Stowers 2010-12-23 11:42:22 UTC
See examples in examples/threading/
Comment 7 Dieter Verfaillie 2010-12-23 21:13:23 UTC
On Windows you only ever want to use gobject.threads_init()
and you should never even need to touch gtk.gdk.threads_init().

gtk.gdk.threads_init() initializes the GDK global lock that
serializes thread access to the GTK and GDK libraries.
As far as I understand, this means all of the sudden multiple
threads can start modifying the GUI. Unlike X11, on Windows
only a single thread is allowed to change the GUI (usually the
main thread is used for this).

The example mentioned above lives here: http://git.gnome.org/browse/pygtk/tree/examples/threading/gtk_threading.py