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 640738 - glib/gtk + twisted main loop is eating up all CPU when a subprocess terminates
glib/gtk + twisted main loop is eating up all CPU when a subprocess terminates
Status: RESOLVED FIXED
Product: pygtk
Classification: Bindings
Component: general
2.22.x
Other Linux
: Normal critical
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
: 638780 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2011-01-27 16:50 UTC by Antoine Martin
Modified: 2011-02-04 09:50 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
This is the obvious patch. This fixes the CPU usage behavior of the example in the comment above. (522 bytes, patch)
2011-01-27 19:31 UTC, Jp Calderone
none Details | Review

Description Antoine Martin 2011-01-27 16:50:41 UTC
This is trivial to reproduce (Fedora 14, Ubuntu 10.10, etc), below is a simple test case, for more details see:
http://twistedmatrix.com/trac/ticket/4658

{{{
#!/usr/bin/python
#import gtk
from twisted.internet import gtk2reactor
gtk2reactor.install()
from twisted.internet import reactor
import subprocess
subprocess.Popen(['sleep', '5'])
#gtk.main()
reactor.run()
}}}
For those that don't know twisted, {{{gtk2reactor.install()}}} ensures that the gtk2 main loop runs when you call {{{reactor.run()}}}

Whether it's twisted or pygtk that makes it misbehave (or the combination of the two)...  users see my application using 100% CPU and I get flamed. Please help!
Comment 1 Antoine Martin 2011-01-27 17:05:43 UTC
Just found that running the reactor with:
reactor.run(installSignalHandlers=False)

Seems to solve this particular problem, although it may have other undesired side effects.
Comment 2 Jp Calderone 2011-01-27 18:35:27 UTC
Consider this pygtk function, particularly the `read` call it contains:

static gboolean
pygtk_main_watch_check(GSource *source)
{
    PyGILState_STATE state;

#ifdef HAVE_PYSIGNAL_SETWAKEUPFD
    PySignalWatchSource *real_source = (PySignalWatchSource *)source;
    GPollFD *poll_fd = &real_source->fd;
    int data_size = 0;
    if (poll_fd->revents & G_IO_IN)
        data_size = read(poll_fd->fd, 0, 1);
#endif

    state = pyg_gil_state_ensure();

    if (PyErr_CheckSignals() == -1 && gtk_main_level() > 0) {
        PyErr_SetNone(PyExc_KeyboardInterrupt);
        gtk_main_quit();
    }

    pyg_gil_state_release(state);

    return FALSE;
}

My understanding of read() is that it can *only* fail with EINVAL with 0 as the 2nd argument.
Comment 3 Jp Calderone 2011-01-27 19:31:57 UTC
Created attachment 179466 [details] [review]
This is the obvious patch.  This fixes the CPU usage behavior of the example in the comment above.
Comment 4 Jp Calderone 2011-01-27 19:55:54 UTC
Here's an even simpler reproduction of the bug:


    import signal
    import gtk

    signal.signal(signal.SIGCHLD, lambda *args: None)
    gtk.main()

Run it, send it SIGCHLD.  CPU usage goes to 100%.
Comment 5 Antoine Martin 2011-01-27 21:19:58 UTC
I've tested the fix against pygtk 2.22.0, it works fine.

Please push this fix asap. 100% cpu usage is clearly not acceptable to users...

I can't modify the title of this bug, but clearly this has nothing to do with twisted (as demonstrated by the simple test case above).
Comment 6 John Stowers 2011-02-03 20:35:40 UTC
This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.
Comment 7 John Stowers 2011-02-03 20:38:59 UTC
*** Bug 638780 has been marked as a duplicate of this bug. ***
Comment 8 Antoine Martin 2011-02-04 09:50:25 UTC
I have filed bugs with all the distros that ship the buggy version, some of them have already pushed a patch for testing (gentoo), some of them didn't need one (debian) and some of them have continued to silently ignore the problem (fedora, ubuntu).

To make it easier to use a patched version of 2.22 (which is used in a lot of places), I have put a copy here:
http://winswitch.org/src/pygtk-2.22.1.tar.bz2
(I use this from jhbuild scripts for example)

I have named it pygtk-2.22.1 since it would seem that pygtk does not issue minor bugfix releases (information from an email conversation on the mailing list):
http://www.mail-archive.com/pygtk@daa.com.au/msg20008.html