Bug: QApplication() raise nothing on tty

Raymond Osborn rayosborn at mac.com
Tue Jul 18 02:10:45 BST 2023


Hi everyone,
I presume this problem is the same as the one that caused NeXpy to start crashing starting with PyQt 5.5 (see https://github.com/nexpy/nexpy/commit/b19480a37e1d14278945672c08cab614a87b15eb). This seemed to be, in my opinion, an unfortunate design decision by Qt to abort a process whenever an error was encountered, in a way that was inaccessible to Python exception handling.

The way to prevent core dumps is to customize or override the sys.excepthook function. You can find an example in the commit that I link to above. If you define your own function, you could use it to raise another Python exception and then utilize the standard Python exception handling methods. In NeXpy, we just report the exception with a GUI message box.

I think there could be an argument for PyQt providing a default way to catch these exceptions by defining its own sys.excepthook function, but it might be difficult to guarantee that such a function doesn’t interfere with other applications that define their own. Perhaps it could be an argument when generating the QApplication instance.

With regards,
Ray Osborn

> On Jul 17, 2023, at 5:08 PM, Florian Bruhin <me at the-compiler.org> wrote:
> 
> Hey,
> 
>> as a real world example please let me show you how much work and action
>> is done in my team just to workaround that problem.
>> 
>> Please see this function [1] and the magic behind [2]. There we
>> figuring out if Qt is available or not because our application is able
>> to run on tty and on X/Wayland.
>> 
>> For more context please visit the related PR [3].
>> 
>> Thanks for your time.
> 
> Right - I'm not saying it's not a problem. But it's not a PyQt bug.
> 
> This is something Qt would need to fix (by providing *some* way to check
> whether a QApplication + GUI is available without crashing when it's
> not), but looking at the relevant issues in the Qt tracker, that doesn't
> seem to be happening:
> 
> https://bugreports.qt.io/browse/QTBUG-106192
> https://bugreports.qt.io/browse/QTBUG-63763
> 
> The fact that Qt aborts the process is a Qt problem, not a PyQt one.
> There's simply no way PyQt can do anything different here.
> 
> Also see a similar consideration in PySide around creating a widget
> without a QApplication: https://bugreports.qt.io/browse/PYSIDE-1451
> Same story there: Python crashes because Qt does, and there's no way for
> that to be changed from a Python wrapper.
> 
> I'll disengage from this conversation at this point, as I feel as I'm
> just repeating myself and we're going in circles.
> 
> Florian

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20230717/4eb2381c/attachment.htm>


More information about the PyQt mailing list