Repository navigation
Closed
Description
Is there a way for an application to signal to prompt_toolkit that it should pretend an EOF has happened (typically making the application exit)? Something like this works with readline but not with prompt_toolkit:
In [1]: import os; f = open(os.devnull); os.dup2(f.fileno(), 0)
In [2]:
Traceback (most recent call last):
File "/usr/local/src/sage-config/local/bin/ipython", line 5, in <module>
start_ipython()
File "/usr/local/src/sage-config/local/lib/python2.7/site-packages/IPython/__init__.py", line 119, in start_ipython
return launch_new_instance(argv=argv, **kwargs)
File "/usr/local/src/sage-config/local/lib/python2.7/site-packages/traitlets/config/application.py", line 596, in launch_instance
app.start()
File "/usr/local/src/sage-config/local/lib/python2.7/site-packages/IPython/terminal/ipapp.py", line 348, in start
self.shell.mainloop()
File "/usr/local/src/sage-config/local/lib/python2.7/site-packages/IPython/terminal/interactiveshell.py", line 402, in mainloop
self.interact()
File "/usr/local/src/sage-config/local/lib/python2.7/site-packages/IPython/terminal/interactiveshell.py", line 385, in interact
code = self.prompt_for_code()
File "/usr/local/src/sage-config/local/lib/python2.7/site-packages/IPython/terminal/interactiveshell.py", line 321, in prompt_for_code
pre_run=self.pre_prompt, reset_current_buffer=True)
File "build/bdist.linux-x86_64/egg/prompt_toolkit/interface.py", line 385, in run
with self.input.raw_mode():
File "build/bdist.linux-x86_64/egg/prompt_toolkit/input.py", line 69, in raw_mode
return raw_mode(self.stdin.fileno())
File "build/bdist.linux-x86_64/egg/prompt_toolkit/terminal/vt100_input.py", line 409, in __init__
self.attrs_before = termios.tcgetattr(fileno)
error: (25, 'Inappropriate ioctl for device')
My use case is a signal handler forcing the application to exit gracefully.
Metadata
Metadata
Assignees
Labels
No labels
Activity
takluyver commentedon Sep 13, 2016
cli.exit()is documented as being equivalent to pressing Ctrl-D.http://python-prompt-toolkit.readthedocs.io/en/latest/pages/reference.html#prompt_toolkit.interface.CommandLineInterface.exit
jdemeyer commentedon Sep 13, 2016
But that does not work asynchronously. I want a solution which would work while
prompt_toolkitis actually waiting for user input.jonathanslenders commentedon Sep 13, 2016
Hi @jdemeyer,
Thanks for this request. I made a pull request that will probably solve the issue: #393
However, I wonder why you would ever dup devnull to fd 0.
jdemeyer commentedon Sep 13, 2016
Because that did the trick for
readline:-)jonathanslenders commentedon May 15, 2018
Closing this now. In prompt_toolkit 2.0, calling
get_app().exit()should close the current application. This can be done in any key binding, and works asynchronously. Please open again or create a new issue if this still doesn't work.techtonik commentedon Jul 5, 2018
This make
promptreturnNone. Not the same as pressing Ctrl+D which raisesEOFError.jonathanslenders commentedon Jul 5, 2018
should probably do it.
techtonik commentedon Jul 5, 2018
It does. Thanks. =)