From 7df2f4d78714707cfb30d83ca99ce84ef9934892 Mon Sep 17 00:00:00 2001 From: "[object Object]" Date: Thu, 28 Jul 2022 15:38:56 -0700 Subject: gh-86128: Add warning to ThreadPoolExecutor docs about atexit behaviour (GH-94008) --- Doc/library/concurrent.futures.rst | 7 +++++++ .../Documentation/2022-06-19-18-18-22.gh-issue-86128.39DDTD.rst | 1 + 2 files changed, 8 insertions(+) create mode 100644 Misc/NEWS.d/next/Documentation/2022-06-19-18-18-22.gh-issue-86128.39DDTD.rst diff --git a/Doc/library/concurrent.futures.rst b/Doc/library/concurrent.futures.rst index 8efbf0a..db5971e 100644 --- a/Doc/library/concurrent.futures.rst +++ b/Doc/library/concurrent.futures.rst @@ -149,6 +149,13 @@ And:: An :class:`Executor` subclass that uses a pool of at most *max_workers* threads to execute calls asynchronously. + All threads enqueued to ``ThreadPoolExecutor`` will be joined before the + interpreter can exit. Note that the exit handler which does this is + executed *before* any exit handlers added using `atexit`. This means + exceptions in the main thread must be caught and handled in order to + signal threads to exit gracefully. For this reason, it is recommended + that ``ThreadPoolExecutor`` not be used for long-running tasks. + *initializer* is an optional callable that is called at the start of each worker thread; *initargs* is a tuple of arguments passed to the initializer. Should *initializer* raise an exception, all currently diff --git a/Misc/NEWS.d/next/Documentation/2022-06-19-18-18-22.gh-issue-86128.39DDTD.rst b/Misc/NEWS.d/next/Documentation/2022-06-19-18-18-22.gh-issue-86128.39DDTD.rst new file mode 100644 index 0000000..bab0068 --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2022-06-19-18-18-22.gh-issue-86128.39DDTD.rst @@ -0,0 +1 @@ +Document a limitation in ThreadPoolExecutor where its exit handler is executed before any handlers in atexit. -- cgit v0.12