Skip to content
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

gh-86128: Add warning to ThreadPoolExecutor docs #94008

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lucaswiman
Copy link

@lucaswiman lucaswiman commented Jun 19, 2022

ThreadPoolExecutor has unusual atexit behavior that can cause threads to block indefinitely. This PR documents that limitation, and adds an explicit warning to the documentation for ThreadPoolExecutor.

See #86128 (comment) for an example where this happens. Essentially, even if it looks like you added an atexit handler to instruct your thread to exit gracefully, it will only be executed after your thread has finished. For long-running threads (e.g. threads listening to a queue), that may never happen at all.

Elsewhere in #86128, it's recommended that ThreadPoolExecutor not be used for long-running tasks, but this was not reflected in the documentation. Based solely on the API, there is no reason to think you shouldn't use it for long-running tasks. The only reason appears to be a limitation in its implementation, so that should be made explicit in the docs.


Thanks very much reviewing!

I'm also open to attempting to fix the underlying odd behavior, though I don't think I have enough context to know what the right fix would be.

@cpython-cla-bot
Copy link

@cpython-cla-bot cpython-cla-bot bot commented Jun 19, 2022

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented Jun 19, 2022

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@bedevere-bot bedevere-bot added the docs label Jun 19, 2022
lucaswiman and others added 2 commits Jun 19, 2022
See python#86128 (comment) for
an example where this happens. Essentially, even if it looks like
you added an `atexit` handler to instruct your thread to exit gracefully,
it will only be executed _after_ your thread has finished. For
long-running threads (e.g. threads listening to a queue), that may
never happen at all.

Elsewhere in python#86128, it's recommended that `ThreadPoolExecutor` not
be used for long-running tasks, but this was not reflected in the
documentation. Based solely on the API, there is no reason to think
you shouldn't use it for long-running tasks. The only reason appears
to be a limitation in its implementation, so that should be made
explicit in the docs.
@lucaswiman lucaswiman force-pushed the document-ThreadPoolExecutor-limitation branch from 4304fc6 to 2bde132 Compare Jun 19, 2022
@lucaswiman
Copy link
Author

@lucaswiman lucaswiman commented Jun 19, 2022

(Note that while this is related to #86128, it does not fix that issue, merely documenting the behavior.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants