PyQt6 on Python 3.14: pyqtSignal(..., object, ...).emit(..., None, ...) corrupts the immortal None refcount (not on 3.13)

Phil Thompson phil at riverbankcomputing.com
Sat Nov 7 11:17:39 GMT 2026


Just to tie this off, it is a bug in Python - see...

https://www.riverbankcomputing.com/pipermail/pyqt/2026-November/046562.html
https://github.com/python/cpython/issues/158401

I will experiment with building using the v3.12 headers as a workaround.

Phil

On 26/10/2026 20:51, Darren Powierski wrote:
> Hi Phil,
> Thanks for the reply. I agree it needs to be shown that this is not a
> CPython bug, so I
> ran more tests, all on one machine with embedded python.org builds.
> 
> 1. PyQt6 6.11.0, Qt 6.11, 100,000 x pyqtSignal(str, object,
> object).emit("k", None, None),
>    reading the None refcount with ctypes before and after:
> 	 Python 3.13.16 (sip 6.15.2): delta 0        (None stays immortal)
> 	 Python 3.14.5  (sip 6.15.2): delta +200,000
> 	 Python 3.15.2  (sip 6.17.0, PyQt6-sip 13.13.0): delta +200,000
>    So it is not specific to 3.14.x; 3.15 behaves the same. The delta
> is exactly one per
>    None argument per emit.
> 
> 2. Same emit with PySide6 6.12.0 on 3.14.5 and 3.15.2: delta 0.
> 
> 3. A minimal C extension (no Qt, no sip) doing 1,000,000 balanced
> Py_INCREF/Py_DECREF and
>    PyTuple_Pack on None, built both with Py_LIMITED_API 3.10 (as in
> the cp310-abi3 PyQt6
>    wheel) and as a native build, MSVC: delta 0 on 3.14.5 and 3.15.2.
> 
> 4. A pure Python / ctypes control (calls, dicts, lists,
> Py_IncRef/Py_DecRef on None):
>    delta 0 on 3.13, 3.14 and 3.15.
> 
> On the same interpreters, only the PyQt6/sip path changes the None
> refcount. That suggests
> an unbalanced Py_DECREF of None (or a missed immortality check) in the
> code that converts
> the object arguments of a signal emit, rather than a CPython fault. I
> have not located the
> exact line, so this is evidence, not proof. If it helps, I can build
> sip/PyQt6 from source
> with a trace in the object-argument conversion.
> 
> Why it matters: in a long-running application (hours) the drift
> eventually produced
> process-wide TypeErrors in json.dumps and "__init__() should return
> None, not NoneType",
> which is why we run on 3.13.
> 
> Reproducer and test sources (repro_none_refcount.py,
> repro_none_refcount_pyside6.py,
> control_no_pyqt.py, nonechurn.c, runchurn.py) are available; I have
> added them below.
> 
> Environment: Windows, PyQt6 6.11.0, PyQt6-Qt6 6.11.x, Qt 6.11.0.
> 
> 
> 
> 
> repro_none_refcount.py
> 
> """Minimal repro: PyQt6 signal emit with None changes the refcount of
> None on Python 3.14.
> 
> None is immortal on 3.12+, so its refcount should never change. On
> 3.14 it grows on
> pyqtSignal(..., object, ...).emit(..., None, ...). Same PyQt6 / Qt /
> sip on 3.13: no change.
> """
> import ctypes
> import os
> import sys
> 
> os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
> from PyQt6 import QtCore, QtWidgets
> from PyQt6.sip import SIP_VERSION_STR
> 
> 
> def none_refcount():
>     return ctypes.c_uint64.from_address(id(None)).value
> 
> 
> class W(QtCore.QObject):
>     sig = QtCore.pyqtSignal(str, object, object)
> 
>     @QtCore.pyqtSlot(str, object, object)
>     def slot(self, a, b, c):
>         pass
> 
> 
> app = QtWidgets.QApplication([])
> w = W()
> w.sig.connect(w.slot)
> 
> N = 100000
> before = none_refcount()
> for _ in range(N):
>     w.sig.emit("k", None, None)
> after = none_refcount()
> 
> print("python", sys.version.split()[0], "| PyQt6",
> QtCore.PYQT_VERSION_STR, "| Qt", QtCore.QT_VERSION_STR,
>       "| sip", SIP_VERSION_STR)
> print("None refcount before: %#x  after: %#x  delta: %d (2 None args x
> %d emits)" % (before, after, after - before, N))
> print("RESULT:", "OK (unchanged)" if after == before else "BUG (None
> refcount changed)")
> 
> 
> repro_none_refcount_pyside6.py
> 
> """Cross-check: same None-through-signal emit using PySide6 instead of 
> PyQt6."""
> import ctypes
> import os
> import sys
> 
> os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
> from PySide6 import QtCore, QtWidgets
> import PySide6
> 
> 
> def none_refcount():
>     return ctypes.c_uint64.from_address(id(None)).value
> 
> 
> class W(QtCore.QObject):
>     sig = QtCore.Signal(str, object, object)
> 
>     @QtCore.Slot(str, object, object)
>     def slot(self, a, b, c):
>         pass
> 
> 
> app = QtWidgets.QApplication([])
> w = W()
> w.sig.connect(w.slot)
> N = 100000
> before = none_refcount()
> for _ in range(N):
>     w.sig.emit("k", None, None)
> after = none_refcount()
> print("python", sys.version.split()[0], "| PySide6", 
> PySide6.__version__)
> print("None refcount before: %#x after: %#x delta: %d" % (before,
> after, after - before))
> print("RESULT:", "OK (unchanged)" if after == before else "BUG (None
> refcount changed)")
> 
> 
> 
> 
> control_no_pyqt.py
> 
> """Control: pure Python / ctypes, no PyQt. Does None's refcount 
> change?"""
> import ctypes
> import sys
> 
> 
> def rc():
>     return ctypes.c_uint64.from_address(id(None)).value
> 
> 
> def f(a, b, c):
>     return (a, b, c)
> 
> 
> b = rc()
> for _ in range(200000):
>     f("k", None, None)
>     d = {"x": None}
>     l = [None, None]
>     ctypes.pythonapi.Py_IncRef(ctypes.py_object(None))
>     ctypes.pythonapi.Py_DecRef(ctypes.py_object(None))
> a = rc()
> print("python", sys.version.split()[0], "before %#x after %#x delta
> %d" % (b, a, a - b))
> 
> 
> 
> 
> 
> nonechurn.c
> 
> /* Minimal extension: balanced INCREF/DECREF on None, no Qt. Built
> twice from this
>    source: -DUSE_ABI3 (Py_LIMITED_API 3.10, like the PyQt6 cp310-abi3
> wheel) and native. */
> #ifdef USE_ABI3
> #define Py_LIMITED_API 0x030A0000
> #endif
> #include <Python.h>
> 
> static PyObject *churn(PyObject *self, PyObject *args)
> {
> 	PyObject *obj;
> 	long n;
> 	if (!PyArg_ParseTuple(args, "Ol", &obj, &n))
> 		return NULL;
> 	for (long i = 0; i < n; i++) {
> 		PyObject *t;
> 		Py_INCREF(obj);
> 		Py_DECREF(obj);
> 		Py_XINCREF(obj);
> 		Py_XDECREF(obj);
> 		t = PyTuple_Pack(2, obj, obj);
> 		Py_XDECREF(t);
> 	}
> 	Py_RETURN_NONE;
> }
> 
> static PyMethodDef M[] = {{"churn", churn, METH_VARARGS, ""}, {NULL,
> NULL, 0, NULL}};
> static struct PyModuleDef D = {PyModuleDef_HEAD_INIT, "nonechurn", 
> NULL, -1, M};
> PyMODINIT_FUNC PyInit_nonechurn(void) { return PyModule_Create(&D); }
> 
> 
> 
> 
> runchurn.py
> 
> import ctypes
> import sys
> sys.path.insert(0, sys.argv[1])
> import nonechurn
> 
> rc = lambda: ctypes.c_uint64.from_address(id(None)).value
> b = rc()
> nonechurn.churn(None, 1000000)
> a = rc()
> print("python", sys.version.split()[0], sys.argv[1].split("\\")[-1],
> "delta", a - b)
> 
> 
> Thank you,
> Darren
> 
> 
> 
> 
> -----Original Message-----
> From: Phil Thompson <phil at riverbankcomputing.com>
> Sent: Monday, 26 October 2026 8:26 PM
> To: Darren Powierski <darren.powierski at tmeic.com.au>
> Cc: pyqt at riverbankcomputing.com
> Subject: Re: PyQt6 on Python 3.14: pyqtSignal(..., object,
> ...).emit(..., None, ...) corrupts the immortal None refcount (not on
> 3.13)
> 
> On 25/10/2026 23:06, Darren Powierski wrote:
>> Hi Phil,
>> 
>> 
>> 
>> I have added a test description of the issue. I am wondering if you
>> can help understand the issue.
> 
> First you have to convince me that this isn't a bug in Python. What
> results do you get with v3.15?
> 
> Phil


More information about the PyQt mailing list