Crash report
What happened?
from concurrent.futures import InterpreterPoolExecutor
executor = InterpreterPoolExecutor()
def f():
import _datetime
print(_datetime)
executor.submit(f)
executor.submit(f)
executor.shutdown()
This code may lead to a interpreter crash:
PS C:\Users\xxx\Source\cpython> .\python.bat .\a.py
Running Debug|x64 interpreter...
<module '_datetime' (built-in)> # The first sub-interpreter's output
Assertion failed: !managed_static_type_index_is_set(self), file C:\Users\xxxxx\Source\cpython\Objects\typeobject.c, line 317
Please note that there is a similar issue may crash the interpreter but in the sestructing phase: #136423
My analyze
The _datetime module will call _PyStaticType_InitForExtension to initialize some static types. Look at it's implementation:
|
int |
|
_PyStaticType_InitForExtension(PyInterpreterState *interp, PyTypeObject *self) |
|
{ |
|
return init_static_type(interp, self, 0, ((self->tp_flags & Py_TPFLAGS_READY) == 0)); |
|
} |
It's using tp_flags Py_TPFLAGS_READY to determine if this type is already initialized. And at last it will call managed_static_type_state_init with the initialized flag.
If the type flag Py_TPFLAGS_READY was not set before, and another sub-interpreter has been initialized, finished, and has set the Py_TPFLAGS_READY flag, this assertion will be triggered:
|
if (initial) { |
|
assert(!managed_static_type_index_is_set(self)); |
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS, Windows
Output from running 'python -VV' on the command line:
Python 3.15.0a0 (heads/main:ba9c1986305, Jul 8 2025, 22:13:18) [MSC v.1943 64 bit (AMD64)]
Linked PRs
Crash report
What happened?
This code may lead to a interpreter crash:
Please note that there is a similar issue may crash the interpreter but in the sestructing phase: #136423
My analyze
The
_datetimemodule will call_PyStaticType_InitForExtensionto initialize some static types. Look at it's implementation:cpython/Objects/typeobject.c
Lines 9269 to 9273 in 490eea0
It's using
tp_flagsPy_TPFLAGS_READYto determine if this type is already initialized. And at last it will callmanaged_static_type_state_initwith the initialized flag.If the type flag
Py_TPFLAGS_READYwas not set before, and another sub-interpreter has been initialized, finished, and has set thePy_TPFLAGS_READYflag, this assertion will be triggered:cpython/Objects/typeobject.c
Lines 316 to 317 in 490eea0
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS, Windows
Output from running 'python -VV' on the command line:
Python 3.15.0a0 (heads/main:ba9c1986305, Jul 8 2025, 22:13:18) [MSC v.1943 64 bit (AMD64)]
Linked PRs
_datetimestatic types during interpreter initialization #136583_datetimestatic types during interpreter initialization (GH-136583) #136943