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

Handle InvalidStateError during termination when using run_in_terminal/patch_stdout. #1926

Merged
merged 1 commit into from
Oct 4, 2024

Conversation

jonathanslenders
Copy link
Member

In some edge cases, during cancellation, probably when using anyio, we can get this InvalidStateError during termination. This patch fixes that bug.

Traceback (most recent call last):
  File "/home/jonathan/git/python-prompt-toolkit/src/prompt_toolkit/application/run_in_terminal.py", line 49, in run
    async with in_terminal(render_cli_done=render_cli_done):
  File "/home/jonathan/.local/share/uv/python/cpython-3.11.10-linux-aarch64-gnu/lib/python3.11/contextlib.py", line 217, in __aexit__
    await anext(self.gen)
  File "/home/jonathan/git/python-prompt-toolkit/src/prompt_toolkit/application/run_in_terminal.py", line 114, in in_terminal
    new_run_in_terminal_f.set_result(None)
asyncio.exceptions.InvalidStateError: invalid state

…al`/`patch_stdout`.

In some edge cases, during cancellation, probably when using anyio, we can get
this `InvalidStateError` during termination. This patch fixes that bug.

```
Traceback (most recent call last):
  File "/home/jonathan/git/python-prompt-toolkit/src/prompt_toolkit/application/run_in_terminal.py", line 49, in run
    async with in_terminal(render_cli_done=render_cli_done):
  File "/home/jonathan/.local/share/uv/python/cpython-3.11.10-linux-aarch64-gnu/lib/python3.11/contextlib.py", line 217, in __aexit__
    await anext(self.gen)
  File "/home/jonathan/git/python-prompt-toolkit/src/prompt_toolkit/application/run_in_terminal.py", line 114, in in_terminal
    new_run_in_terminal_f.set_result(None)
asyncio.exceptions.InvalidStateError: invalid state
```
@jonathanslenders jonathanslenders merged commit c12ac91 into master Oct 4, 2024
12 checks passed
@jonathanslenders jonathanslenders deleted the fix-invalid-state-error branch October 4, 2024 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant