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.1k stars 717 forks source link

Error `Bad file descriptor` during using prompt-toolkit with xonsh #1853

Open anki-code opened 4 months ago

anki-code commented 4 months ago

Hey! I see many stable repeatable cases when prompt-toolkit shows the Bad file descriptor error. It makes xonsh shell users sad.

You can find the latest most repeatable report in this comment.

Please help to fix this.

Thanks!

anki-code commented 4 months ago

@jonathanslenders sorry for direct mention but it's very annoying issue and help will be very appreciated.

anki-code commented 4 months ago

I found that issue appeared starting from prompt-toolkit 3.0.41 where asyncio was introduced (https://github.com/prompt-toolkit/python-prompt-toolkit/commit/8c601936b11d91388edc653df80aa34bd9cb1606).

After this commit xonsh users continuously facing with this:

```python Traceback (most recent call last): File "/opt/homebrew/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 73, in close loop.run_until_complete(loop.shutdown_default_executor()) File "/opt/homebrew/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 640, in run_until_complete self.run_forever() File "/opt/homebrew/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 607, in run_forever self._run_once() File "/opt/homebrew/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 1884, in _run_once event_list = self._selector.select(timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/selectors.py", line 566, in select kev_list = self._selector.control(None, max_ev, timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ KeyboardInterrupt During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/opt/homebrew/lib/python3.11/site-packages/xonsh/main.py", line 469, in main sys.exit(main_xonsh(args)) ^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/xonsh/main.py", line 513, in main_xonsh shell.shell.cmdloop() File "/opt/homebrew/lib/python3.11/site-packages/xonsh/ptk_shell/shell.py", line 405, in cmdloop line = self.singleline(auto_suggest=auto_suggest) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/xonsh/ptk_shell/shell.py", line 373, in singleline line = self.prompter.prompt(**prompt_args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/prompt_toolkit/shortcuts/prompt.py", line 1026, in prompt return self.app.run( ^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/prompt_toolkit/application/application.py", line 1002, in run return asyncio.run(coro) ^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 189, in run with Runner(debug=debug) as runner: File "/opt/homebrew/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 63, in __exit__ self.close() File "/opt/homebrew/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 77, in close loop.close() File "/opt/homebrew/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/unix_events.py", line 68, in close super().close() File "/opt/homebrew/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/selector_events.py", line 91, in close self._close_self_pipe() File "/opt/homebrew/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/selector_events.py", line 99, in _close_self_pipe self._ssock.close() File "/opt/homebrew/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/socket.py", line 503, in close self._real_close() File "/opt/homebrew/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/socket.py", line 497, in _real_close _ss.close(self) OSError: [Errno 9] Bad file descriptor Xonsh encountered an issue during launch Failback to /bin/zsh ```