abi3 wheels drift the refcount of None; on Python 3.14 None loses immortality after ~1e9 calls
Phil Thompson
phil at riverbankcomputing.com
Sat Nov 7 16:42:43 GMT 2026
On 04/11/2026 11:18, Cong Nguyen Thanh wrote:
> Hi,
> With the PyQt6 cp310-abi3 wheels (6.11.0, and also the latest 6.12.0)
> on
> CPython 3.14.7 (Windows x64), every PyQt6 method that returns None adds
> +1
> to the raw refcount of None, and that +1 is never taken back. Methods
> that
> return other values add nothing; True/False are not affected.
> On Python 3.14, None starts at a refcount of 0xC0000000 and stays
> immortal
> only while bit 31 is set, so there is a margin of 2**30 (~1.07e9).
> After
> that many calls, None stops being immortal and the 3.14 interpreter
> starts
> failing its own None checks. Every Python-level __init__ then raises:
> TypeError: __init__() should return None, not 'NoneType'
> Logging, warnings, pandas etc. all break, and the process stays broken
> until restart.
> In practice this is reached in under 2 hours by the common pattern
> while w.isVisible():
> app.processEvents()
> since every iteration is +1 (about 160k/s in our application).
> My guess is that the abi3 .pyd files are compiled against pre-3.12
> Python
> headers, where Py_INCREF(Py_None) is a plain ob_refcnt++ that knows
> nothing
> about immortal objects, while 3.14 never decrements immortal objects.
> Building the abi3 wheels against Python >= 3.12 headers (still
> targeting
> the 3.10 limited API) should fix it. PyAV 19 and protobuf fixed the
> same
> problem this way.
> The attached script shows the +1 per call in a few seconds; run it with
> --full to reproduce the TypeError (about 5 minutes).
> Output on my machine:
> Python 3.14.7, PyQt6 6.11.0, Qt 6.11.0
> None refcount at start: low32=0xc0000000 ob_overflow=0
> QPoint.setX() None refcount delta per call: +1.00
> QObject.setObjectName() None refcount delta per call: +1.00
> QApplication.processEvents() None refcount delta per call: +1.00
> QPoint.x() [returns int] None refcount delta per call: +0.00
> Related CPython issue: https://github.com/python/cpython/issues/158401
> Best regards,
> Thanh Nguyen
Experimentation shows that building against v3.14 headers is the only
version that works for all supported versions of Python.
Theoretically v3.15 should work as well but it drops
PyWeakref_GetObject() from the limited API (prematurely IMHO).
I'll build against v3.14 for future releases (and snapshots).
Thanks,
Phil
More information about the PyQt
mailing list