Python/gc.c:533: visit_decref: Assertion "!_PyObject_IsFreed(op)" failed
Enable tracemalloc to get the memory block allocation traceback
object address : 0x7fcfb75797f0
object refcount : 2
object type : 0x55a7d0ea0140
object type name: dict
object repr : [1] 38419 segmentation fault (core dumped) /home/peter/develop/cpython/python a.py
Sometimes an ImportCycleError shows up before the crash as well:
Traceback (most recent call last):
File "/home/peter/develop/cpython/b.py", line 1, in <module>
lazy import a
ImportError: deferred import of 'a' raised an exception during resolution
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/peter/develop/cpython/a.py", line 6, in <module>
something()
~~~~~~~~~^^
File "/home/peter/develop/cpython/a.py", line 4, in something
b.hello()
~~~~~~~^^
File "/home/peter/develop/cpython/b.py", line 4, in hello
print(a)
^
File "/home/peter/develop/cpython/a.py", line 6, in <module>
something()
~~~~~~~~~^^
File "/home/peter/develop/cpython/a.py", line 4, in something
b.hello()
~~~~~~~^^
File "/home/peter/develop/cpython/b.py", line 4, in hello
print(a)
^
ImportCycleError: cannot import name 'a' (most likely due to a circular import)
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Activity
robsdedude commented on Feb 12, 2026
Can no longer reproduce the crash since gh-144733 has been merged.
However, the same code works when doing the lazy import manually, i.e.,
Reading the PEP, I'm not quite sure whether this is supposed to work with lazy imports or not.
ZeroIntensity commented on Feb 12, 2026
Thanks, I missed that PR.
@pablogsal No test case for #144733? This seems like a fairly common thing to try.
pablogsal commented on Feb 12, 2026
Do you want to open a PR adding it?
pythongh-144727: Add test for circular lazy import crash (python#144727)
pablogsal commented on Feb 15, 2026
Opened #144838
pythongh-144727: Add test for circular lazy import crash (python#144727)
gh-144727: Add test for circular lazy import crash (#144727) (#144838)
pythongh-144727: Add test for circular lazy import crash (python#144727…
pythongh-144727: Add test for circular lazy import crash (python#144727…