Python 3.13+Exceptionsexception
PythonFinalizationError
built-in exceptions
An operation is blocked during interpreter finalization (3.13+).
Syntax
raise PythonFinalizationError
New in 3.13 and a subclass of RuntimeError; it fires when code attempts something forbidden while the interpreter is shutting down — starting a thread, forking, spawning a subprocess. The usual culprit is work scheduled too late: a __del__, an atexit hook, or a daemon thread still trying to finish. The cure is finishing and joining background work before exit rather than catching the error; before 3.13 the same situation surfaces as a plain RuntimeError.
Examples
try:
raise PythonFinalizationError
except PythonFinalizationError as e:
print(type(e).__name__) # → PythonFinalizationError
See also
Open in the full glossarydocs.python.orgReport an inaccuracy