prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.11k stars 718 forks source link

Improve termination of Application. Don't ever suppress CancelledError. #1689

Closed jonathanslenders closed 1 year ago

jonathanslenders commented 1 year ago

This fixes a race condition when the prompt_toolkit Application gets cancelled while waiting for the background tasks to complete. Catching CancelledError at this point caused any code following the Application.run_async to continue, instead of being cancelled.

In the future, we should probably adapt task groups (from anyio or Python 3.11), but until then, this is sufficient.