qt5reactor icon indicating copy to clipboard operation
qt5reactor copied to clipboard

Hang on Windows when closing the last window

Open aalex opened this issue 8 years ago • 6 comments

Using the qt5reactor with pyqt5 on Windows 7, the Python script hangs once we closed the window.

Here is a code example: https://gist.github.com/aalex/c469f7031e2747e1fec9a64536fb0917

aalex avatar Sep 11 '17 21:09 aalex

FYI, I launched the application and closed the window and it terminated. This was on Kubuntu 16.04 with latest qt5reactor (4f6d5921b2155a9180d92ad607a08189ed07734a).

altendky@tp:~/aalex$ venv/bin/python -m pip freeze
attrs==17.2.0
Automat==0.6.0
constantly==15.1.0
hyperlink==17.3.1
incremental==17.5.0
PyQt5==5.9
qt5reactor==0.4
sip==4.19.3
six==1.10.0
Twisted==17.5.0
zope.interface==4.4.2

altendky avatar Sep 12 '17 01:09 altendky

Yes: I tested it on Ubuntu 16.04 xenial64, as well.

Le 11 sept. 2017 21 h 51, "Kyle Altendorf" [email protected] a écrit :

FYI, I launched the application and closed the window and it terminated. This was on Kubuntu 16.04 with latest qt5reactor (4f6d592 https://github.com/sunu/qt5reactor/commit/4f6d5921b2155a9180d92ad607a08189ed07734a ).

altendky@tp:~/aalex$ venv/bin/python -m pip freeze attrs==17.2.0 Automat==0.6.0 constantly==15.1.0 hyperlink==17.3.1 incremental==17.5.0 PyQt5==5.9 qt5reactor==0.4 sip==4.19.3 six==1.10.0 Twisted==17.5.0 zope.interface==4.4.2

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/sunu/qt5reactor/issues/15#issuecomment-328708056, or mute the thread https://github.com/notifications/unsubscribe-auth/AAR7LdkIxzcYevM9n699QlX5n_JbCWOBks5sheO6gaJpZM4PT0xl .

aalex avatar Sep 12 '17 03:09 aalex

Same issue here. @sunu @crwood Any update on this? :)

NeatMonster avatar Mar 21 '18 18:03 NeatMonster

According to the docstring (and confirmed by the code), "calling reactor.stop() will unhook twisted but leave your Qt application running". To me, this suggests that calling reactor.stop() is an insufficient way of exiting the application entirely (and would seem to explain why the script in the gist above hangs: the reactor appears to shut down, but the Qt event loop remains running).

That said, changing the gist's closeEvent() to call QCoreApplication.instance().quit() instead of reactor.stop(), exits the application cleanly for me. Maybe this should be considered the "proper" way of exiting a qt5reactor-based application? Has anybody been able to reproduce a hang when exiting this way instead?

crwood avatar May 10 '18 19:05 crwood

CloseEvent() when called , if you already have a deferred thread running then the on reactor.stop() the thread still keeps running even on close event.

The cleanest way is QCoreApplication.instance().quit()

incognitozen avatar May 13 '20 13:05 incognitozen

I'm adding a twisted app to my Qt5 GUI application and the following works for me: https://gist.github.com/altendky/faf48446c335418dac8793635d119750#file-qt5reactor_threads_run-py However I'm still having issues with my "exit" menu item implementation. It signals my Qt thread to stop and calls join, but hangs and does not close the application Adding: twisted.internet.reactor._stopThreadPool() to that call prevents the hang and my application exits now, but I get the following output from twisted:

2022-04-19 21:22:49+0000 [-] Unhandled error in Deferred: 2022-04-19 21:22:49+0000 [-] Unhandled Error (unable to obtain traceback): 'IncrementalDecoder' object has no attribute 'errors'

So it seems like I'm still not doing something right.

Without the _stopThreadPool() command, my application hangs on sys.exit(0).

I replaced the sys.exit() w/ os._exit() and that now gives me a clean exit w/no need for a reactor.stop. I don't really understand why this works and sys.exit() does not, but at least it works.

brookbot avatar Apr 19 '22 21:04 brookbot