Opened 12 years ago

Closed 12 years ago

#933 closed bug (WontFix)

Issue with glib, threads and SIGCHLD eating 100% cpu

Reported by: Plisk Owned by: andar
Priority: minor Milestone:
Component: Unknown Version:
Keywords: cpu Cc:

Description

As it turned out if gtk2reactor is used instead of gtk.main() then after subprocess.Popen-ed process finishes deluge starts to eat 100% cpu. A simple examle:

import os

import pygtk
pygtk.require('2.0')
import gtk

from twisted.internet import gtk2reactor
from twisted.internet.protocol import ProcessProtocol
reactor = gtk2reactor.install()

def on_button_clicked(button):
    #import subprocess
    #subprocess.Popen(['mplayer', '/mnt/d/11.avi'])
    reactor.spawnProcess(ProcessProtocol(), 'mplayer',
                         ['mplayer', '/mnt/d/11.avi'],
                         os.environ)

sw = gtk.ScrolledWindow()
win = gtk.Window()
win.connect('delete-event', gtk.main_quit)
button = gtk.Button(u"Press me!")
button.connect("clicked", on_button_clicked)
vbox = gtk.VBox()
vbox.pack_start(button, gtk.FALSE)
win.add(vbox)
win.show_all()

reactor.run()
#gtk.main()

I tried to change subprocess.Popen to reactor.spawnProcess as twisted docs suggest but nothing changed. If in above example we change reactor.run() to gtk.main() and use subprocess.Popen - then no cpu eating occurs, but leaving zombie though, which we can address later i think, as it is not so important as issue with reactor.

Can gtkui be changed back to use gtk.main() ?

Change History (7)

comment:1 Changed 12 years ago by andar

As far as I can tell, gtk.main() is called from the reactor.run() and if you don't call reactor.run() then the twisted loop will not run..

comment:2 Changed 12 years ago by Plisk

  • Milestone set to 1.2.0
  • Version changed from 1.1.7 to 1.2.0_dev

comment:3 Changed 12 years ago by andar

I just tried the above code and I had it start vlc, I then closed vlc and checked for the cpu usage and it was normal.. So I cannot reproduce this..

comment:4 Changed 12 years ago by Plisk

So i debugged it a bit more and it resulted in this:

import signal, subprocess

import gtk, gobject
gobject.threads_init()

def on_button_clicked(button):
    subprocess.Popen(['xine', '/mnt/d/Movies/AI.avi'])

win = gtk.Window()
win.connect('delete-event', gtk.main_quit)
button = gtk.Button(u"Press me!")
button.connect("clicked", on_button_clicked)
vbox = gtk.VBox()
vbox.pack_start(button, gtk.FALSE)
win.add(vbox)
win.show_all()

def sig_handler(num, frame):
    print 11
signal.signal(signal.SIGCHLD, sig_handler)

gtk.main()

Twisted calls behind the scenes gobject.threads_init() and sets SIGCHLD handler. Somehow because of this happens that cpu usage 100%... If i remove gobject.threads_init() or that SIGCHLD handler - its OK then. So its something has to do with threads i guess...

comment:5 Changed 12 years ago by Plisk

  • Summary changed from Issue with twisted's gtk2reactor eating 100% cpu to Issue with glib, threads and SIGCHLD eating 100% cpu

Made the test case more simple. Now i'm stuck.

import signal, subprocess

import gobject, glib

def sig_handler(num, frame):
    print 11

gobject.threads_init()
signal.signal(signal.SIGCHLD, sig_handler)

subprocess.Popen('xine')

glib.MainLoop().run()

comment:6 Changed 12 years ago by andar

  • Milestone 1.2.0 deleted
  • Version 1.2.0_dev deleted

comment:7 Changed 12 years ago by andar

  • Resolution set to wontfix
  • Status changed from new to closed

This is a bug in pygtk: https://bugzilla.gnome.org/show_bug.cgi?id=481569

Relevant twisted bug: http://twistedmatrix.com/trac/ticket/3096

This is not a bug with Deluge, so closing.

Note: See TracTickets for help on using tickets.