Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-88110: clear concurrent.futures.thread._threads_queues after fork #101940

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
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-88110: clear concurrent.futures.thread._threads_queues after fork
Threads are gone after fork, so clear the queues too. Otherwise the
child process (here created via multiprocessing.Process) crashes on
interpreter exit with:

    Traceback (most recent call last):
      File "/usr/lib64/python3.11/multiprocessing/popen_fork.py", line 72, in _launch
        code = process_obj._bootstrap(parent_sentinel=child_r)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/lib64/python3.11/multiprocessing/process.py", line 332, in _bootstrap
        threading._shutdown()
      File "/usr/lib64/python3.11/threading.py", line 1561, in _shutdown
        atexit_call()
      File "/usr/lib64/python3.11/concurrent/futures/thread.py", line 31, in _python_exit
        t.join()
      File "/usr/lib64/python3.11/threading.py", line 1109, in join
        raise RuntimeError("cannot join current thread")
    RuntimeError: cannot join current thread

Fixes #88110
  • Loading branch information
marmarek committed Feb 15, 2023
commit cf472e1ec860e278b10e9aee53d9e56968c85bed
1 change: 1 addition & 0 deletions Lib/concurrent/futures/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def _python_exit():
os.register_at_fork(before=_global_shutdown_lock.acquire,
after_in_child=_global_shutdown_lock._at_fork_reinit,
after_in_parent=_global_shutdown_lock.release)
os.register_at_fork(after_in_child=_threads_queues.clear)


class _WorkItem(object):
Expand Down