8000 Can't import `concurrent.futures.thread` at shutdown · Issue #113060 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

Can't import concurrent.futures.thread at shutdown #113060

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pitrou opened this issue Dec 13, 2023 · 5 comments
Closed

Can't import concurrent.futures.thread at shutdown #113060

pitrou opened this issue Dec 13, 2023 · 5 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@pitrou
Copy link
Member
pitrou commented Dec 13, 2023

Bug report

Bug description:

Simple reproducer (real-world bug report is a bit more complex):

import threading


def use_cf():
    import concurrent.futures.thread


def main():
    t = threading.Thread(target=use_cf)
    t.start()


if __name__ == "__main__":
    main()

CPython versions tested on:

3.10, 3.11, 3.12, 3.13

Operating systems tested on:

No response

@pitrou pitrou added type-bug An unexpected behavior, bug, or error stdlib Python modules in the Lib dir labels Dec 13, 2023
@pitrou
Copy link
Member Author
pitrou commented Dec 13, 2023

I don't know if we want to do anything about this, I'm just posting just in case.

@gpshead

@gpshead
Copy link
Member
gpshead commented Dec 14, 2023

In general we consider this working as intended (from the linked bug):

$ python main.py 
Traceback (most recent call last):
  File "pyarrow/pandas-shim.pxi", line 100, in pyarrow.lib._PandasAPIShim._check_import
  File "pyarrow/pandas-shim.pxi", line 48, in pyarrow.lib._PandasAPIShim._import_pandas
  File "/home/jleibs/pyarrow-repro/venv/lib/python3.10/site-packages/pyarrow/pandas_compat.py", line 24, in <module>
    import concurrent.futures.thread  # noqa
  File "/usr/lib/python3.10/concurrent/futures/thread.py", line 37, in <module>
    threading._register_atexit(_python_exit)
  File "/usr/lib/python3.10/threading.py", line 1504, in _register_atexit
    raise RuntimeError("can't register atexit after shutdown")
RuntimeError: can't register atexit after shutdown

After the main interpreter thread has exited, launching new threads isn't really supported.

This has been true since 3.9 thanks to b61b818 which resolved Issue #83993 via PR #19149.

@gpshead gpshead closed this as completed Dec 14, 2023
@gpshead gpshead reopened this Dec 14, 2023
@gpshead gpshead closed this as not planned Won't fix, can't repro, duplicate, stale Dec 14, 2023
@pitrou
Copy link
Member Author
pitrou commented Dec 14, 2023

The problem isn't launching new threads here, it's simply importing the module. In other words, c.f.thread is imported as a side effect of the user importing another module after shutdown has started, even though the executor functionality wouldn't have been used anyway. It is of course possible to workaround by catching the RuntimeError, but it's a bit of a pointless annoyance.

@pitrou
Copy link
Member Author
pitrou commented Dec 14, 2023

In general, I think it's a good idea for module import to be graceful, even though it can be complicated to achieve in some cases (and concurrent.futures is of course a complex module).

@gpshead
Copy link
Member
gpshead commented Dec 14, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
Development

No branches or pull requests

2 participants
0