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
With PYTHON_LAZY_IMPORTS=all, I get a segfault with pandas being initialized inside a freezegun, likely because GC frees it somehow.
Tested with freezegun==1.5.5 and pandas==3.0.6, require 2 files below
lib.py
importpandas
repro.py
importlibfromfreezegunimportfreeze_timefor_inrange(2): # the first call is fine, the second crasheswithfreeze_time("2024-01-01"):
pass
Calling it
$ PYTHON_LAZY_IMPORTS=all python repro.py
Fatal Python error: Segmentation fault
Current thread ... (most recent call first):
Garbage-collecting
File "<frozen importlib._bootstrap_external>", line 500 in _compile_bytecode
...
freezegun runs dir() and getattr() over every module. That getattr resolves the lazy pandas reference, but if i try to reproduce without freezegun, it gives an error but no segfault
$ PYTHON_LAZY_IMPORTS=all python repro-python.py
File "pandas/_libs/tslibs/np_datetime.pyx", line 33, in init pandas._libs.tslibs.np_datetime
File ".../numpy/__init__.cython-30.pxd", line 1081, in numpy.import_array
ImportError: numpy._core.multiarray failed to import
Possibly related to #158402 or #159266 but very different crashes
CPython versions tested on:
3.15
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.15.0 (main, Oct 9 2026, 15:24:40) [Clang 22.1.3 ]
The GC crash also reproduces without lazy imports on Python 3.12, and without freezegun by replacing datetime classes before importing a small Cython extension. The native stack recurses between the extension traversal callback and subtype_traverse().
Cython's native datetime declarations currently resolve mutable module attributes. The proposed fix in cython/cython#8059 now supports C type objects in extern declarations generically. datetime.pxd obtains the native types from PyDateTime_CAPI; the compiler has no datetime-specific handling. The interface remains under review. Downstream extensions would need regeneration and rebuilding.
There is also a separate pandas initialization problem: its option-registration and datetime/parser capsule imports can be deferred in global lazy mode. pandas-dev/pandas#71173 tracks that, and pandas-dev/pandas#71178 proposes explicit initialization imports.
With both proposed changes and rebuilt pandas, the reworked fix passes the original two-file scenario in five fresh Linux processes with empty stderr and no CPython source changes. The reduced C/C++ regressions pass on Windows and Linux, including free-threaded CPython. This does not establish general pandas compatibility with global lazy imports: a separate Timestamp import cycle remains.
A verified workaround is to initialize pandas with normal imports before entering freeze_time:
Activity
zolaski333 commentedon Oct 14, 2026
The GC crash also reproduces without lazy imports on Python 3.12, and without freezegun by replacing datetime classes before importing a small Cython extension. The native stack recurses between the extension traversal callback and subtype_traverse().
Cython's native datetime declarations currently resolve mutable module attributes. The proposed fix in cython/cython#8059 now supports C type objects in extern declarations generically. datetime.pxd obtains the native types from PyDateTime_CAPI; the compiler has no datetime-specific handling. The interface remains under review. Downstream extensions would need regeneration and rebuilding.
There is also a separate pandas initialization problem: its option-registration and datetime/parser capsule imports can be deferred in global lazy mode. pandas-dev/pandas#71173 tracks that, and pandas-dev/pandas#71178 proposes explicit initialization imports.
With both proposed changes and rebuilt pandas, the reworked fix passes the original two-file scenario in five fresh Linux processes with empty stderr and no CPython source changes. The reduced C/C++ regressions pass on Windows and Linux, including free-threaded CPython. This does not establish general pandas compatibility with global lazy imports: a separate Timestamp import cycle remains.
A verified workaround is to initialize pandas with normal imports before entering freeze_time: