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

Kyle Altendorf sda at fstab.net
Fri Sep 22 19:09:42 BST 2023


This is not a direct response to your question, so I'll keep it short, but just wanted to make sure you are aware of pytest-qt.  Also, async tooling like whichever is the current asyncio qt integration, qtreactor (twisted), and qtrio (trio) may provide insight into coexisting with qt.

Cheers,
-kyle

On Fri, Sep 22, 2023, at 12:35, Stefan Seefeld wrote:
> Hello,
> 
> I'm trying to establish a Python test methodology whereby a QApplication is launched (and its event loop executed) in a secondary thread, while the primary thread performs some "test scenario".
> Summary: I'm unable to set this up, and it isn't clear why this isn't working.
> 
> Details: please consider the attached test file (executed with `pytest -vs qt-minimal-test,py`).
> 
> In this minimal test case, the actual test function body is empty. A "fixture" function is used to set up the system, i.e. launch a thread to construct the application showing only a "quit" button.
> 
> Consider these cases:
> 
> 0.  run the above command, wait for the test passing being reported on the console, then click the "quit" button. This appears to be working as expected.
> 
> 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
> 
> 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
> 
> Any idea why the above happens ?
> 
> Many thanks for any help you can offer !
> 
> 
> 
> --
> 
>       ...ich hab' noch einen Koffer in Berlin...
> 
> 
> *Attachments:*
>  • qt-minimal-test.py
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20230922/a34f5bc3/attachment.htm>


More information about the PyQt mailing list