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.25k stars 714 forks source link

OSError Bad file descriptor #433

Open mitnk opened 7 years ago

mitnk commented 7 years ago

Hello,

Encounter OSError when using prompt-toolkit in xonsh:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/xonsh/ptk/shortcuts.py", line 108, in prompt
    document = cli.run(reset_current_buffer=False)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/prompt_toolkit/interface.py", line 394, in run
    self.eventloop.run(self.input, self.create_eventloop_callbacks())
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/prompt_toolkit/eventloop/posix.py", line 93, in run
    self.add_reader(self._schedule_pipe[0], None)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/prompt_toolkit/eventloop/posix.py", line 280, in add_reader
    self.selector.register(fd)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/prompt_toolkit/eventloop/select.py", line 75, in register
    sel.register(fd)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/prompt_toolkit/eventloop/select.py", line 130, in register
    self._sel.register(fd, selectors.EVENT_READ, None)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/selectors.py", line 536, in register
    self._kqueue.control([kev], 0, 0)
OSError: [Errno 9] Bad file descriptor

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/bin/xonsh", line 3, in <module>
    main()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/xonsh/main.py", line 276, in main
    shell.shell.cmdloop()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/xonsh/ptk/shell.py", line 132, in cmdloop
    line = self.singleline(auto_suggest=auto_suggest)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/xonsh/ptk/shell.py", line 101, in singleline
    line = self.prompter.prompt(**prompt_args)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/xonsh/ptk/shortcuts.py", line 113, in prompt
    eventloop.close()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/prompt_toolkit/eventloop/posix.py", line 270, in close
    os.close(schedule_pipe[0])
OSError: [Errno 9] Bad file descriptor

Was running a command like cat foo.json | py -m json.tool. Cannot reproduce it anymore. Could it be an issue on PTK side?

jonathanslenders commented 7 years ago

Hi @mitnk,

Thanks for reporting this issue! Right now, I'm not sure what's going on, but I'll try to reproduce it.

Could it be that you were running Xonsh already for a long time at the point of this crash? I wonder whether we're somewhere leaking a file descriptor. Or whether our os.pipe() call failed earlier.

mitnk commented 7 years ago

It was just opened xonsh, not for long time at all. I'm not sure it is something special I did, or it's a temporary issue of xonsh of that time, or PTK. not sure at all :)

I may close this issue if no one encounter this anymore.

nexuhan commented 5 years ago

Encountered this on Mac OS X (Mojave) error on first and subsequent runs of https://github.com/cloudnativelabs/kube-shell and https://github.com/awslabs/aws-shell