running pyqt app event loop in secondary thread, using (Py)Qt6.5
Stefan Seefeld <[email protected]> Fri, 22 Sep 2023 12:35:52 -0400
| Newsgroups | gmane.comp.lib.qt.general,gmane.comp.python.pyqt-pykde |
|---|---|
| Message-ID | <CAOEGfx3CH87ogrmCcbsy=Y=0hjnzm6K0T6vFC_m=6rOvsfWAsA@mail.gmail.com> |
--0000000000005ae5120605f5343f
Content-Type: multipart/alternative; boundary="0000000000005ae50f0605f5343d"
--0000000000005ae50f0605f5343d
Content-Type: text/plain; charset="UTF-8"
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...
--0000000000005ae50f0605f5343d
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>Hello,</div><div><br></div><div>I'm trying to est=
ablish a Python test methodology whereby a QApplication is launched (and it=
s event loop executed) in a secondary thread, while the primary thread perf=
orms some "test scenario".</div><div>Summary: I'm unable to s=
et this up, and it isn't clear why this isn't working.</div><div><b=
r></div><div>Details: please consider the attached test file (executed with=
`pytest -vs qt-minimal-test,py`).<br></div><div><br></div><div>In this min=
imal test case, the actual test function body is empty. A "fixture&quo=
t; function is used to set up the system, i.e. launch a thread to construct=
the application showing only a "quit" button.<br></div><div><br>=
</div><div>Consider these cases:</div><div><br></div><div>0.=C2=A0 run the =
above command, wait for the test passing being reported on the console, the=
n click the "quit" button. This appears to be working as expected=
.</div><div><br></div><div>1. run the above command, but click the "qu=
it" button immediately. Thus results in the error message `<span style=
=3D"font-family:monospace"><span style=3D"color:rgb(0,0,0);background-color=
:rgb(255,255,255)">QObject::killTimer: Timers cannot be stopped from anothe=
r thread`,</span><br></span></div><div><span style=3D"font-family:monospace=
">
followed by a segmentation fault<br></span></div><div><span style=3D"font-f=
amily:monospace"><br></span></div><div><span style=3D"font-family:monospace=
">2. rather than just "yielding" to the test function, yield the =
application object (so the test function can interact with it). No matter w=
hen you click the "quit" button, the result is the same as in 1.<=
/span></div><div><span style=3D"font-family:monospace"><br></span></div><di=
v><span style=3D"font-family:monospace">3. call `h.app.quit()` after he `yi=
eld` (i.e. as soon as the test function completes). Result: the application=
becomes unresponsive, but doesn't stop</span></div><div><span style=3D=
"font-family:monospace"><br></span></div><div><span style=3D"font-family:mo=
nospace">Any idea why the above happens ?<br></span></div><div><span style=
=3D"font-family:monospace"><br></span></div><div><span style=3D"font-family=
:monospace">Many thanks for any help you can offer !<br></span></div><div><=
br></div><div><br></div><div><br><span class=3D"gmail_signature_prefix">-- =
</span><br><div dir=3D"ltr" class=3D"gmail_signature" data-smartmail=3D"gma=
il_signature"><div dir=3D"ltr"><div><img src=3D"https://ci3.googleuserconte=
nt.com/mail-sig/AIorK4yh4RzsqlxV6irScDGRVZ8a7NRCh_INtpPsAHx2Y8v4Vu3VKsI54RF=
Ns3YRZk_2xTTtMMdSCzdNrf5XRUlmF4BkezmtZv-j5c3A4G0hEA"></div><div><pre> =
...ich hab' noch einen Koffer in Berlin...
</pre></div></div></div></div></div>
--0000000000005ae50f0605f5343d--
--0000000000005ae5120605f5343f
Content-Type: text/x-python; charset="US-ASCII"; name="qt-minimal-test.py"
Content-Disposition: attachment; filename="qt-minimal-test.py"
Content-Transfer-Encoding: base64
Content-ID: <f_lmutnwfy0>
X-Attachment-Id: f_lmutnwfy0
aW1wb3J0IHRocmVhZGluZwppbXBvcnQgdGltZQppbXBvcnQgc3lzCmltcG9ydCBweXRlc3QKCgpj
bGFzcyBIZWxwZXI6CiAgICBkZWYgX19pbml0X18oc2VsZik6CiAgICAgICAgc2VsZi5hcHAgPSBO
b25lCgogICAgZGVmIGxhdW5jaChzZWxmKToKICAgICAgICBmcm9tIFB5UXQ2LlF0Q29yZSBpbXBv
cnQgUVNpemUsIFF0CiAgICAgICAgZnJvbSBQeVF0Ni5RdFdpZGdldHMgaW1wb3J0IFFBcHBsaWNh
dGlvbiwgUU1haW5XaW5kb3csIFFQdXNoQnV0dG9uCgogICAgICAgIGNsYXNzIE1haW5XaW5kb3co
UU1haW5XaW5kb3cpOgogICAgICAgICAgICBkZWYgX19pbml0X18oc2VsZik6CiAgICAgICAgICAg
ICAgICBzdXBlcigpLl9faW5pdF9fKCkjIwoKICAgICAgICAgICAgICAgIHNlbGYuc2V0V2luZG93
VGl0bGUoIlRlc3QgQXBwIikKICAgICAgICAgICAgICAgIGJ1dHRvbiA9IFFQdXNoQnV0dG9uKCJx
dWl0IikKICAgICAgICAgICAgICAgIHNlbGYuc2V0Q2VudHJhbFdpZGdldChidXR0b24pCiAgICAg
ICAgICAgICAgICBidXR0b24uY2xpY2tlZC5jb25uZWN0KFFBcHBsaWNhdGlvbi5xdWl0KQoKICAg
ICAgICBzZWxmLmFwcCA9IFFBcHBsaWNhdGlvbihzeXMuYXJndikKICAgICAgICB3aW5kb3cgPSBN
YWluV2luZG93KCkKICAgICAgICB3aW5kb3cuc2hvdygpCiAgICAgICAgcHJpbnQoJ3N0YXJ0aW5n
IGV2ZW50IGxvb3AnKQogICAgICAgIHNlbGYuYXBwLmV4ZWMoKQogICAgICAgIHByaW50KCdldmVu
dCBsb29wIGRvbmUnKQoKCkBweXRlc3QuZml4dHVyZQpkZWYgYXBwbGljYXRpb24oKToKICAgIGgg
PSBIZWxwZXIoKQogICAgdGhyZWFkID0gdGhyZWFkaW5nLlRocmVhZCh0YXJnZXQ9aC5sYXVuY2gp
CiAgICB0aHJlYWQuc3RhcnQoKQogICAgcHJpbnQoJ3NldHVwIGRvbmUnKQogICAgIyBjYXNlIDA6
IHdhaXQgZm9yIHRlc3QgdG8gcGFzcywgdGhlbiBjbGljayAicXVpdCIgYnV0dG9uLiB0ZXN0IHdv
cmtzIGFzIGV4cGVjdGVkLgogICAgIyBjYXNlIDE6IGNsaWNrICJxdWl0IiBidXR0b24gcHJpb3Ig
dG8gdGVzdCBwYXNzaW5nLiB0ZXN0IHNlZ2ZhdWx0cwogICAgdGltZS5zbGVlcCg1KQogICAgIyBj
YXNlIDI6IHJlcGxhY2UgdGhlIG5leHQgbGluZSBieSAieWllbGQgaC5hcHAiLiB0ZXN0IHNlZ2Zh
dWx0cwogICAgeWllbGQKICAgICMgY2FzZSAzOiB1bmNvbW1lbnQuIHRlc3Qgc2VnZmF1bHRzCiAg
ICAjIGguYXBwLnF1aXQoKQogICAgdGhyZWFkLmpvaW4oKQogICAgcHJpbnQoJ3RlYXJkb3duIGRv
bmUnKQoKCmRlZiB0ZXN0X2FwcChhcHBsaWNhdGlvbik6CiAgICBwcmludCgncnVubmluZyBzY2Vu
YXJpbycpCg==
--0000000000005ae5120605f5343f
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Interest mailing list
[email protected]
https://lists.qt-project.org/listinfo/interest
--0000000000005ae5120605f5343f--