GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Circular lazy import results in a crash · Issue #144727 · python/cpython

Circular lazy import results in a crash #144727

New issue
Copy link
New issue
Copy link
Closed
Closed
Circular lazy import results in a crash#144727
Copy link
Labels
3.15bugs and security fixesbugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump

Description

@ZeroIntensity
ZeroIntensity
opened on Feb 12, 2026
Issue body actions

Crash report

What happened?

Not even 3 hours since PEP 810 got merged, we already have a crash!

# a.py
lazy import b

def something():
    b.hello()

something()
# b.py
lazy import a

def hello():
    print(a)

Running a.py will result in the following crash:

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:

No response

Linked PRs

  • gh-144727: Add test for circular lazy import crash (#144727) #144838
Reacted by Sergey Miryanov, Furkan Onder and Srinivas Reddy Thatiparthy (తాటిపర్తి శ్రీనివాస్ రెడ్డి)

Activity

  1. ZeroIntensity
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    type-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
    3.15bugs and security fixesbugs and security fixes
    on Feb 12, 2026
  2. robsdedude commented on Feb 12, 2026

    @robsdedude
    robsdedude
    on Feb 12, 2026
    Contributor
    More actions

    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.,

    # a.py
    def something():
        import b
        b.hello()
    
    something()
    # b.py
    def hello():
        import a
        print(a)

    Reading the PEP, I'm not quite sure whether this is supposed to work with lazy imports or not.

  3. ZeroIntensity commented on Feb 12, 2026

    @ZeroIntensity
    ZeroIntensity
    on Feb 12, 2026
    MemberAuthor
    More actions

    Thanks, I missed that PR.

    @pablogsal No test case for #144733? This seems like a fairly common thing to try.

  4. pablogsal commented on Feb 12, 2026

    @pablogsal
    pablogsal
    on Feb 12, 2026
    Member
    More actions

    Thanks, I missed that PR.

    @pablogsal No test case for #144733? This seems like a fairly common thing to try.

    Do you want to open a PR adding it?

  5. pablogsal
    added a commit that references this issue on Feb 15, 2026

    pythongh-144727: Add test for circular lazy import crash (python#144727)

    663c89f
  6. pablogsal commented on Feb 15, 2026

    @pablogsal
    pablogsal
    on Feb 15, 2026
    Member
    More actions

    Opened #144838

  7. pablogsal
    added 2 commits that reference this issue on Feb 15, 2026

    pythongh-144727: Add test for circular lazy import crash (python#144727)

    e8ea062

    gh-144727: Add test for circular lazy import crash (#144727) (#144838)

    5fe139c
  8. pablogsal
    closed this as completedon Feb 15, 2026
  9. brijkapadia
    added a commit that references this issue on Feb 28, 2026

    pythongh-144727: Add test for circular lazy import crash (python#144727…

    baa8a32
  10. ljfp
    added a commit that references this issue on Apr 25, 2026

    pythongh-144727: Add test for circular lazy import crash (python#144727…

    c75f9bd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.15bugs and security fixesbugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.