-
Notifications
You must be signed in to change notification settings - Fork 4
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
Warn when the Qt application quits 'early' #267
Conversation
Codecov Report
@@ Coverage Diff @@
## main #267 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 35 35
Lines 2023 2036 +13
Branches 138 139 +1
=========================================
+ Hits 2023 2036 +13
Continue to review full report at Codecov.
|
@vxgmichel, would you like to review or test this before I merge? Does it fulfill your interest in a notification? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍
I ran a quick test with the problem I originally faced with #262. I was surprised to not see the warning appear before I realized two Qt applications were created:
- one in
qtrio.run
- and another one in the main async function
Weirdly enough, this caused the aboutToQuit
signal of the first application to not be emitted. Once I made sure the app was created before running qtrio.run
, the PR worked as expected.
That's... super weird. The Qt application is a singleton. You shouldn't be able to have two. >>> from PySide2 import QtCore
>>> a1 = QtCore.QCoreApplication([])
>>> a2 = QtCore.QCoreApplication([])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: Please destroy the QCoreApplication singleton before creating a new QCoreApplication instance. But with PyQt5 it does let you do that... uh... >>> from PyQt5 import QtCore
>>> a1 = QtCore.QCoreApplication([])
>>> a2 = QtCore.QCoreApplication([])
>>> a1
<PyQt5.QtCore.QCoreApplication object at 0x7f3c88b0e550>
>>> a2
<PyQt5.QtCore.QCoreApplication object at 0x7f3c8584d4c0> And PyQt6 (6.1.1) still does. >>> from PyQt6 import QtCore
>>> a1 = QtCore.QCoreApplication([])
>>> a2 = QtCore.QCoreApplication([])
>>> a1
<PyQt6.QtCore.QCoreApplication object at 0x7f73ce8b0550>
>>> a2
<PyQt6.QtCore.QCoreApplication object at 0x7f73ce7e80d0> |
https://doc.qt.io/qt-6/qcoreapplication.html
So it apparently isn't a singleton at the C++ level, you are just supposed to not create multiple. Someone did some experimentation for us as to what the implications of having multiple applications are. I recreated the signal separation issue. from PyQt6 import QtCore
a1 = QtCore.QCoreApplication([])
a2 = QtCore.QCoreApplication([])
def f1():
print("f1")
def f2():
print("f2")
a1.applicationNameChanged.connect(f1)
a2.applicationNameChanged.connect(f2)
print("---")
a1.applicationNameChanged.emit()
print("---")
a2.applicationNameChanged.emit()
print("---")
Anyways, I think I'll leave dealing with multiple application instances as a separate activity, if it gets handled at all. The shutdown aspects are a thing I think are appropriate for QTrio to make efforts on since QTrio is necessarily tied up in the lifetime of the application. Creating multiple applications is just a thing you shouldn't do regardless. |
Follows from #262.