Skip to content

gh-152915: Add ExecutorShutdownError to concurrent.futures#153003

Open
zainnadeem786 wants to merge 1 commit into
python:mainfrom
zainnadeem786:fix/executor-shutdown-error
Open

gh-152915: Add ExecutorShutdownError to concurrent.futures#153003
zainnadeem786 wants to merge 1 commit into
python:mainfrom
zainnadeem786:fix/executor-shutdown-error

Conversation

@zainnadeem786

Copy link
Copy Markdown
Contributor

Summary

This PR introduces concurrent.futures.ExecutorShutdownError, a typed exception raised when work is submitted to an executor that can no longer accept new futures because it has been shut down.

The new exception subclasses RuntimeError, preserving backward compatibility while allowing callers to distinguish executor shutdown from unrelated runtime failures without relying on exception message matching.

Changes

  • Add ExecutorShutdownError to concurrent.futures.
  • Export the new public exception from concurrent.futures.
  • Update ThreadPoolExecutor.submit() to raise ExecutorShutdownError after:
    • explicit executor shutdown
    • interpreter shutdown
  • Update ProcessPoolExecutor.submit() to raise ExecutorShutdownError after:
    • explicit executor shutdown
    • interpreter shutdown
  • Preserve the existing exception messages.
  • Update the concurrent.futures test suite.
  • Update the documentation.
  • Add a Library NEWS entry.

InterpreterPoolExecutor inherits the updated thread executor behavior, so no additional implementation changes were required.

Backward Compatibility

ExecutorShutdownError subclasses RuntimeError, so existing code catching RuntimeError continues to work unchanged while enabling callers to distinguish executor shutdown from unrelated runtime failures.

Close gh-152915

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33437092 | 📁 Comparing ddb1def against main (8b1dbb1)

  🔍 Preview build  

2 files changed
± library/concurrent.futures.html
± whatsnew/changelog.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a typed exception for concurrent.futures executor shutdown

1 participant