Skip to content

Import system deadlocks in multithreading environments when performing circular imports #125037

@Jerem2360

Description

@Jerem2360

Bug report

Bug description:

Hello,
By pure chance, I have found the following, which I consider as a bug for reasons that will appear in the description of said bug.

Suppose we have the following python modules:

foomodule.py:

import threading

msg = "hello from foo"


from barmodule import baz


t = threading.Thread(target=baz)
t.start()
t.join()

barmodule.py

def baz():
    import foomodule
    print('baz', foomodule.msg)

If we run this code with the command python foomodule.py, the program hangs forever. However, a normal python user would probably expect this to not happen as the thread is in principle meant to run in parallel of the code following the t.start() call.
I do know that the lock on which it is waiting is used to protect the import system from race conditions, but the point is that this deadlock is not detected and the user gets no error message or warning telling them they may have done something wrong (in this case a circular import through multiple threads), which is why I consider this as a bug.

Hope someone reviews this bug report and can fix this issue.
Regards,
Jerem2360.

CPython versions tested on:

3.12

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions