[PyQt] Exception within Slot causes Abort

Florian Bruhin me at the-compiler.org
Sun Mar 20 11:44:21 GMT 2016


* Dave Gradwell <davegradwell at yahoo.co.uk> [2016-03-20 10:55:26 +0000]:
> Appreciated, but if I raise an exception within a slot then Python
> is aborted; I can't really catch anything 'up chain' and handle it
> appropriately because the entire Python process is being torn
> down/aborted.

How would you handle the exception in your example (with the QTimer)
either way? You aren't in control when Qt will call that function
(from C++), so I don't see how you could.

If I'm understanding things right, there's only really two choices
PyQt can take here - either it *needs to* return something to the C++
caller (which is usually some default value for the given type, and
that in turn can invoke undefined behaviour), or it bails out using
abort().

That's why in earlier PyQt versions, with such exceptions, you only
see a stacktrace printed out, but your application continues to run
(potentially with undefined behaviour). Bailing out seems to be the
far safer choice.

See [1] for some backstory and [2]/[3] for the discussion where this
was implemented for some more backstory.

[1] https://www.riverbankcomputing.com/pipermail/pyqt/2014-September/034806.html
[2] https://www.riverbankcomputing.com/pipermail/pyqt/2014-September/034873.html
[3] https://www.riverbankcomputing.com/pipermail/pyqt/2014-October/034888.html

> But, in the more boring/normal situation, if I raise an exception
> elsewhere (ie outside of a slot), Python is not aborted, throws the
> exception 'up chain' and, if not otherwise caught, nicely writes the
> error out as an error and continues.

No, it doesn't continue. It quits.

> There may be ways to defeat qFatal() issuing the Abort (installing a
> different logger?) but that doesn't seem like the right thing to do. 

Using a custom sys.excepthook, e.g. to show a crash window or so.

Florian

-- 
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
         I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160320/665cbbf4/attachment.sig>


More information about the PyQt mailing list