question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jonathanslenderscommented, Jul 5, 2018
get_app().exit(exception=EOFError)

should probably do it.

1reaction
jdemeyercommented, Sep 13, 2016

cli.exit() is documented as being equivalent to pressing Ctrl-D.

But that does not work asynchronously. I want a solution which would work while prompt_toolkit is actually waiting for user input.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to continue reading file when encountering fake EOF?
I try to read a file use Python. Notepad show that there are 200 lines. f = open('record.txt', 'r') for line in f.readlines():...
Read more >
A fake EOF is reached by pressing continuously the key to display ...
A fake EOF is reached by pressing continuously the key to display the next frame from the H.264 videos from the M2TS, MTS,...
Read more >
Handling end-of-file (eof) correctly
The eof() function, as in infile.eof() , is a bool function which is true if the EOF character has been read, false otherwise....
Read more >
libspectre does not handle correctly when a FAKE %%EOF in the ...
FWIW I don't think it's a fake EOF. It is part of an embedded EPS file. The specification is not very clear about...
Read more >
The eof Member Function
Every input file stream has a member function called eof, that can be used ... read past the end of the input file,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found