Python 3.11 and QObject.destroyed signals: _PyThreadState_PopFrame: Assertion `tstate->datastack_top >= base' failed
Florian Bruhin
me at the-compiler.org
Wed Jul 13 11:39:33 BST 2022
On Fri, Jul 08, 2022 at 05:30:27PM +0200, Florian Bruhin wrote:
> when testing my application with the current Python 3.11 beta, I've
> noticed a bug which seems to be triggered somehow by something PyQt
> does: https://github.com/python/cpython/issues/93252
>
> This is the most trivial reproducer I could find:
>
> from PyQt5.QtCore import QObject
>
> def run():
> obj = QObject()
> for _ in range(202):
> obj.destroyed.connect(lambda: None)
>
> run()
>
> Which crashes CPython with:
>
> python: Python/pystate.c:2201: _PyThreadState_PopFrame: Assertion `tstate->datastack_top >= base' failed.
FWIW, we ended up finding a much simpler reproducer, not involving PyQt:
def f():
pass
for _ in range(203):
try:
f(None)
except:
pass
Thus this happened when a stack frame can't be built up - Python never
cleaned it properly in that case. It's been fixed in 3.11.0b4:
https://github.com/python/cpython/pull/94708/commits/be41a146c6595200107cb3ece97809cb506dffba
I don't quite understand why/how the connection to QObject.destroyed
exhibits the same behavior, but in any case, the patch fixes it.
Florian
--
me at the-compiler.org | https://www.qutebrowser.org
https://bruhin.software/ | https://github.com/sponsors/The-Compiler/
GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
I love long mails! | https://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20220713/a0aa55a5/attachment.sig>
More information about the PyQt
mailing list