Exceptions quit mainloop.

Simon McVittie simon.mcvittie at collabora.co.uk
Thu Sep 18 08:33:56 PDT 2008


On Thu, 18 Sep 2008 at 12:29:42 +0100, Heston James - Cold Beans wrote:
> I have a situation which I've seen arise recently within an application
> built in python using the dbus gobject mainloop whereby when uncaught
> exceptions occur within the application it doesn't crash gracefully and I
> get sprawls or logging data spat back to the command line and the
> application continues to run.

Yes. This is because of the main loop code in pygobject (not dbus-python).
dbus-python throws out stack traces to the Python 'logging' module
(which defaults to sending them to stderr), because the alternative
would be for the information to be lost entirely!

> I'm looking for a sure fire way that any uncaught exceptions which occur in
> the application will cause the mainloop to quit and the application to stop
> running properly, I can then have the system relaunch it.

Sorry, I wish there was one.

> I'm thinking perhaps something like this might work:
> 
>         # Attempt to run the mainloop.
>         try:
>             # Call for the mainloop to run.
>             main_loop.run()
>         # Catch any exceptions which may occur.
>         except Exception, e:
>             # An exception occurred within the application.
>             # Log the exception which has occurred.
>             self.__logger.critical("FATAL EXCEPTION OCCURRED: %s" % str(e))
>             # Quit the mainloop.
>             main_loop.quit()

I wish it was that simple... but no, uncaught exceptions do not
terminate run().

    Simon
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 155 bytes
Desc: Digital signature
Url : http://lists.freedesktop.org/archives/dbus/attachments/20080918/f824eace/attachment.pgp 


More information about the dbus mailing list