You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PyGILStateEnsure() (Probably) Crashes If Called After Finalization #124619
I'm pretty sure PyGILState_Ensure() will crash if called after finalization, particularly in the case where the thread doesn't already have a thread state active. I noticed this while looking at the function for something else.
Hitting what looks like this same crash in real-world (non-synthetic) code, via PyGObject + GDBus, on Python 3.14.7 — so this is still unfixed on stable 3.14, not just the 3.14.0a7 build from #132948.
Reproducer:powerprofilesctl get (a short-lived Python script shipped with power-profiles-daemon, using PyGObject to talk to power-profiles-daemon over D-Bus). It queries the current profile, prints it, and exits. Invoked frequently (once per status-bar poll interval) it segfaults intermittently with SIGSEGV / SEGV_MAPERR.
coredumpctl info backtrace of the crashing thread (a GDBus worker thread, not the main thread):
Frame #0 is unresolved (no debug symbols on this build), but given PyEval_RestoreThread → PyGILState_Ensure directly above it, it's almost certainly the same _PyThreadState_Attach/bind_gilstate_tstate path as the original report.
At the same instant, the main thread is already inside exit():
Mechanism appears to be: the main thread finishes and calls exit(), kicking off interpreter finalization, while a GDBus-owned worker thread is mid-g_object_unref on a proxy/connection object and its GObject finalizer calls back into Python (PyGObject's _gi), which calls PyGILState_Ensure() on a thread state that finalization has already begun tearing down.
Reproduced twice on this machine so far (identical stack both times), a few days apart, under ordinary desktop use — no synthetic thread-spam required, just a program that talks to D-Bus from a background thread and exits promptly afterward. Given power-profiles-daemon, NetworkManager's Python bindings, and plenty of other GLib/GDBus-using Python tools follow this same "spin up async D-Bus, do one thing, exit" pattern, this is likely to affect more than just this one tool as more distros ship 3.14.
Activity
PyGILState_Ensurecalled from background thread during finalization on Python 3.14.0a7 #132948 as a duplicate of this issueSccucci84 commentedon Sep 1, 2026
Hitting what looks like this same crash in real-world (non-synthetic) code, via PyGObject + GDBus, on Python 3.14.7 — so this is still unfixed on stable 3.14, not just the 3.14.0a7 build from #132948.
Reproducer:
powerprofilesctl get(a short-lived Python script shipped withpower-profiles-daemon, using PyGObject to talk topower-profiles-daemonover D-Bus). It queries the current profile, prints it, and exits. Invoked frequently (once per status-bar poll interval) it segfaults intermittently withSIGSEGV/SEGV_MAPERR.coredumpctl infobacktrace of the crashing thread (a GDBus worker thread, not the main thread):Frame #0 is unresolved (no debug symbols on this build), but given
PyEval_RestoreThread→PyGILState_Ensuredirectly above it, it's almost certainly the same_PyThreadState_Attach/bind_gilstate_tstatepath as the original report.At the same instant, the main thread is already inside
exit():Mechanism appears to be: the main thread finishes and calls
exit(), kicking off interpreter finalization, while a GDBus-owned worker thread is mid-g_object_unrefon a proxy/connection object and its GObject finalizer calls back into Python (PyGObject's_gi), which callsPyGILState_Ensure()on a thread state that finalization has already begun tearing down.Reproduced twice on this machine so far (identical stack both times), a few days apart, under ordinary desktop use — no synthetic thread-spam required, just a program that talks to D-Bus from a background thread and exits promptly afterward. Given
power-profiles-daemon,NetworkManager's Python bindings, and plenty of other GLib/GDBus-using Python tools follow this same "spin up async D-Bus, do one thing, exit" pattern, this is likely to affect more than just this one tool as more distros ship 3.14.Poll the active power profile over D-Bus instead of powerprofilesctl