Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Circular lazy import results in a crash #144727

Copy link
Copy link
@ZeroIntensity

Description

@ZeroIntensity
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

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.15pre-release feature fixes, bugs and security fixespre-release feature fixes, bugs 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
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.