Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hang on Windows when closing the last window #15

Open
aalex opened this issue Sep 11, 2017 · 6 comments
Open

Hang on Windows when closing the last window #15

aalex opened this issue Sep 11, 2017 · 6 comments

Comments

@aalex
Copy link

aalex commented Sep 11, 2017

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

@altendky
Copy link
Member

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

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

@aalex
Copy link
Author

aalex commented Sep 12, 2017 via email

@NeatMonster
Copy link

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

@crwood
Copy link
Collaborator

crwood commented May 10, 2018

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?

@incognitozen
Copy link

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()

@brookbot
Copy link

brookbot commented Apr 19, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants