ipython / ipython/ipython

Replacement for '[raw_]input()' that allows inputhooks (and GUI integration) to run?

Open
#10,396 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
16.8k
Forks
4.5k
Avg merge
1d 2h
Merged PRs (30d)
6

Description

In IPython 4 and below, the GUI integration used PyOS_InputHook to run GUI event loops. This function not only gets called when waiting at the prompt, but also when waiting for `[raw_]input()` to complete. Thus, GUI apps still run fine while a function uses `[raw_]input()` to wait for something. (Yes, yes, this is a silly thing to do; the functon should block on an event in the GUI. Still, this is often quite expedient for one-off type tasks.)

However, in IPython 5, prompt_toolkit's eventloop/inputhook mechanism is used for GUI integration instead. So while `[raw_]input()` blocks, the GUI event loop will not run, and the GUIs will hang.

It's possible to use prompt_toolkit to create a replacement for `[raw_]input()` that does run the correct inputhook:
```python
import IPython
import prompt_toolkit
def ip_input(message=''):
ip = IPython.get_ipython()
el = prompt_toolkit.shortcuts.create_eventloop(ip.inputhook)
return prompt_toolkit.prompt(message, eventloop=el)
```
Is this something that IPython should provide by default? (As an method on the InteractiveShell instance? In the main interactive namespace? Or even shadowing the built-in `[raw_]input()` function?)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.