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
Error Bad file descriptor
in prompt_toolkit
> 3.0.40
#5241
Comments
Just to add link to #4224 |
OSError: [Errno 9] Bad file descriptor
at pretty random operationsBad file descriptor
in prompt_toolkit
I can reproduce this on Mac in case of alias with group of commands: pip install 'xonsh[full]'
xonsh --no-rc
aliases['ttt'] = 'echo 1 && echo 2'
ttt
# 1
# 2
# <Press enter>
# <Press enter>
# Exception: 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 |
Bad file descriptor
in prompt_toolkit
Bad file descriptor
in prompt_toolkit
I found that issue appeared starting from prompt-toolkit 3.0.41 where To fix this just downgrade the prompt-toolkit version: xpip uninstall -y prompt-toolkit
xpip install prompt-toolkit==3.0.40 The issue was reported to upstream - prompt-toolkit/python-prompt-toolkit#1853 |
@gforsyth hey! Please see my comment above. It looks like this issue is pretty critical because creates unstable behavior e.g. I see this report in news.ycombinator.com. May be we need to pin prompt-toolkit to |
I believe this is the only way for now, though popular packages such as IPython do require newer |
Bad file descriptor
in prompt_toolkit
Bad file descriptor
in prompt_toolkit>3.0.40
Bad file descriptor
in prompt_toolkit>3.0.40
Bad file descriptor
in prompt_toolkit
> 3.0.40
I'll be at a computer later and can take a look. In the mean time, if someone can PR the upper pin and add a note to the docs that'll make it faster to release. |
Thanks @anki-code -- merged and released 0.15.0. Going to leave this issue open until we sort out the upstream issue or figure out what part of xonsh is tripping up prompt toolkit |
@gforsyth @anki-code this bug persists even after this fix - but much less |
I confirm this. The simple cases like alias for I'm also facing with this during typing the command: File "/opt/homebrew/lib/python3.11/site-packages/xonsh/main.py", line 470, in main
sys.exit(main_xonsh(args))
^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/xonsh/main.py", line 514, in main_xonsh
shell.shell.cmdloop()
File "/opt/homebrew/lib/python3.11/site-packages/xonsh/ptk_shell/shell.py", line 406, in cmdloop
line = self.singleline(auto_suggest=auto_suggest)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/xonsh/ptk_shell/shell.py", line 374, in singleline
line = self.prompter.prompt(**prompt_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/prompt_toolkit/shortcuts/prompt.py", line 1024, in prompt
return self.app.run(
^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/prompt_toolkit/application/application.py", line 973, in run
return loop.run_until_complete(coro)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 9] Bad file descriptor |
Bug upstream introduced in version 3.0.41 causes xonsh to randomly crash. See xonsh/xonsh#5241
Possible to just bundle the correct version of This blows up for me with a simple |
hi @gnat! Can you test and confirm this - #5241 (comment) ? Downgrading prompt toolkit solves the issue? |
#5241 (comment) is probably not a viable solution for the AppImage version of xonsh. See: |
@gnat thanks for the test! Your test is a bit not correct because you reinstall package without restart xonsh. And after restart I have no confidence that during the run xonsh will use the older version because newer one is packed to AppImage but you can try. Please read the section about running xonsh in the cheatsheet. Meanwhile I created PR with pinning version for AppImage. See #5356. |
@gnat I think you can unpack AppImage, reinstall ptk, and test: cd /tmp
wget https://github.com/xonsh/xonsh/releases/download/0.15.1/xonsh-x86_64.AppImage
chmod +x xonsh-x86_64.AppImage
./xonsh-x86_64.AppImage --appimage-extract
./xonsh-x86_64/bin/xonsh
xpip uninstall prompt-toolkit
xpip install prompt-toolkit==3.0.40
exit
./xonsh-x86_64/bin/xonsh |
@gforsyth possible to get a tag/release for a new appimage? Thank you! |
@gnat new version have come, please test |
@anki-code No go, sadly, with 0.16 AppImage |
@gnat please provide more details: Workaround: |
@jnoortheen hey! I'm randomly getting the asyncio errors from ptk. Maybe it's related to ptk releases maybe to xonsh releases maybe to python 3.12 release. You had an afforts around using asyncio and I treat you as an expert in this. Could you please take a look into this? It's annoying issue. If you have not enough time could you please share your thoughts and maybe links to docs that I can read to have knowledge. I've caught this now for my xonsh-installed env: Exception ignored in: <function BaseEventLoop.__del__ at 0x106479ee0>
Traceback (most recent call last):
File "/Users/pc/.local/xonsh-env/lib/python3.12/asyncio/base_events.py", line 726, in __del__
self.close()
File "/Users/pc/.local/xonsh-env/lib/python3.12/asyncio/unix_events.py", line 68, in close
super().close()
File "/Users/pc/.local/xonsh-env/lib/python3.12/asyncio/selector_events.py", line 104, in close
self._close_self_pipe()
File "/Users/pc/.local/xonsh-env/lib/python3.12/asyncio/selector_events.py", line 112, in _close_self_pipe
self._ssock.close()
File "/Users/pc/.local/xonsh-env/lib/python3.12/socket.py", line 504, in close
self._real_close()
File "/Users/pc/.local/xonsh-env/lib/python3.12/socket.py", line 498, in _real_close
_ss.close(self)
OSError: [Errno 9] Bad file descriptor
echo 1 | asdTraceback (most recent call last):
File "/Users/pc/.local/xonsh-env/lib/python3.12/site-packages/xonsh/main.py", line 470, in main
sys.exit(main_xonsh(args))
^^^^^^^^^^^^^^^^
File "/Users/pc/.local/xonsh-env/lib/python3.12/site-packages/xonsh/main.py", line 514, in main_xonsh
shell.shell.cmdloop()
File "/Users/pc/.local/xonsh-env/lib/python3.12/site-packages/xonsh/ptk_shell/shell.py", line 406, in cmdloop
line = self.singleline(auto_suggest=auto_suggest)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pc/.local/xonsh-env/lib/python3.12/site-packages/xonsh/ptk_shell/shell.py", line 374, in singleline
line = self.prompter.prompt(**prompt_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pc/.local/xonsh-env/lib/python3.12/site-packages/prompt_toolkit/shortcuts/prompt.py", line 1024, in prompt
return self.app.run(
^^^^^^^^^^^^^
File "/Users/pc/.local/xonsh-env/lib/python3.12/site-packages/prompt_toolkit/application/application.py", line 973, in run
return loop.run_until_complete(coro)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pc/.local/xonsh-env/lib/python3.12/asyncio/base_events.py", line 672, in run_until_complete
self.run_forever()
File "/Users/pc/.local/xonsh-env/lib/python3.12/asyncio/base_events.py", line 639, in run_forever
self._run_once()
File "/Users/pc/.local/xonsh-env/lib/python3.12/asyncio/base_events.py", line 1947, in _run_once
event_list = self._selector.select(timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pc/.local/xonsh-env/lib/python3.12/selectors.py", line 566, in select
kev_list = self._selector.control(None, max_ev, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 9] Bad file descriptor
Xonsh encountered an issue during launch
Failback to /bin/zsh UPD: I catched this exception again. I suppose that after another process was stopped. |
Testing environment: macOS Sonoma 14.1.2
After a git checkout, or directory change I very randomly get the following error:
Don't know how to force reproduction of this bug since it occurs very randomly at different times (but pretty often)
The text was updated successfully, but these errors were encountered: