running pyqt app event loop in secondary thread, using (Py)Qt6.5

Jeremy Katz jkatz at volexity.com
Fri Sep 22 18:15:47 BST 2023


On 9/22/23 09:35, Stefan Seefeld wrote:

> 1. run the above command, but click the "quit" button immediately. Thus 
> results in the error message `QObject::killTimer: Timers cannot be 
> stopped from another thread`,
> followed by a segmentation fault

My guess is that the QApplication object is being destroyed by the 
garbage collector, which isn't running in the QApplication's thread. 
Adding an explicit `del self.app` after the QApplication.exec returns 
prevents the crash for me.

This strategy likely won't work (AFAIK...) on macOS. While Qt is 
relatively happy to run in any thread, the mac UI interface must be used 
from the initial thread.

> 2. rather than just "yielding" to the test function, yield the 
> application object (so the test function can interact with it). No 
> matter when you click the "quit" button, the result is the same as in 1.
> 
> 3. call `h.app.quit()` after he `yield` (i.e. as soon as the test 
> function completes). Result: the application becomes unresponsive, but 
> doesn't stop

2 and possibly 3 sound like more instances of a wrong thread situation.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0x67F18D5A76753BBB.asc
Type: application/pgp-keys
Size: 3147 bytes
Desc: OpenPGP public key
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20230922/b2046430/attachment.key>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20230922/b2046430/attachment.sig>


More information about the PyQt mailing list