GNOME Bugzilla – Bug 702552
regression: idle handler is not unregistered if callback throws exception
Last modified: 2013-07-03 09:02:38 UTC
Example: from gi.repository import Gtk, GObject def cb(): raise RuntimeError("foo") def exit(): Gtk.main_quit() GObject.idle_add(cb) GObject.timeout_add(3000, exit) Gtk.main() You'll see the idle callback loop until the timeout hits. Bisected to this commit: commit 1b27432abf6004553e9476d5ffeb2bf603534419 Author: Martin Pitt <martinpitt@gnome.org> Date: Wed Oct 24 08:50:37 2012 +0200 Remove static idle_add/timeout_add bindings Pretty serious IMO since apps could just start randomly eating tons of CPU if an exception is hit at an inopportune time.
*** Bug 702634 has been marked as a duplicate of this bug. ***
As Christoph points out in bug 702634, there are a couple of ways this can be fixed (which are not mutually exclusive): 1. Clear out ffi return values to some default depending on gi return type if a python exception occurs. 2. Special case each method in overrides to return specific values if an exception occurs. The handle_exception utility from GenericTreeModel can be moved into "gi" and used for this, see: https://git.gnome.org/browse/pygobject/tree/pygtkcompat/generictreemodel.py?h=pygobject-3-8#n51 https://git.gnome.org/browse/pygobject/tree/pygtkcompat/generictreemodel.py?h=pygobject-3-8#n216
Created attachment 248280 [details] [review] Clear return value of closures to zero when an exception occures For return types other than void, set the ffi closure return argument to 0 when a Python exception occures. This a good default in general but also has the side affect of fixing failing idle callbacks by causing them to be removed from main loops (after their stack is printed).
The above patch is intended for both PyGObject 3.8 and 3.9.
Comment on attachment 248280 [details] [review] Clear return value of closures to zero when an exception occures Thanks Simon!
Attachment 248280 [details] pushed as 1aa76b8 - Clear return value of closures to zero when an exception occures
Pushed to both 3.8 and master.