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 702552 - regression: idle handler is not unregistered if callback throws exception
regression: idle handler is not unregistered if callback throws exception
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: general
Git master
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
: 702634 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2013-06-18 12:27 UTC by Cole Robinson
Modified: 2013-07-03 09:02 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Clear return value of closures to zero when an exception occures (2.59 KB, patch)
2013-07-03 06:19 UTC, Simon Feltman
committed Details | Review

Description Cole Robinson 2013-06-18 12:27:53 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.
Comment 1 Simon Feltman 2013-06-19 14:22:43 UTC
*** Bug 702634 has been marked as a duplicate of this bug. ***
Comment 2 Simon Feltman 2013-06-19 14:50:09 UTC
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
Comment 3 Simon Feltman 2013-07-03 06:19:30 UTC
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).
Comment 4 Simon Feltman 2013-07-03 06:20:13 UTC
The above patch is intended for both PyGObject 3.8 and 3.9.
Comment 5 Martin Pitt 2013-07-03 08:36:02 UTC
Comment on attachment 248280 [details] [review]
Clear return value of closures to zero when an exception occures

Thanks Simon!
Comment 6 Simon Feltman 2013-07-03 08:57:30 UTC
Attachment 248280 [details] pushed as 1aa76b8 - Clear return value of closures to zero when an exception occures
Comment 7 Simon Feltman 2013-07-03 09:02:38 UTC
Pushed to both 3.8 and master.