[IPython-dev] IPython inputhook, higher rate?
Erik Bray
erik.m.bray at gmail.com
Wed Oct 1 13:25:57 EDT 2014
Hi Martin,
On Tue, Sep 30, 2014 at 11:05 AM, Martin Teichmann
<lkb.teichmann at gmail.com> wrote:
> Hi,
>
> I just saw this thread about why and how the python
> inputhook works, and how to integrate other event loops
> with IPython, using said input hooks.
>
> The actual problem is that the python input routine blocks
> while it reads from the console. This is completely
> unnecessary, as the underlying GNU readline library does
> not require a block at all. Down in the python interpreter,
> something like the following happens (it's in C in original).
>
> while True:
> PyOS_InputHook()
> select(stdin, timeout=100)
> if something_in_stdin:
> call_GNU_readline_to_read_one_char()
>
> so, python defines its own event loop! As one can see
> very clearly, from the IPython standpoint this is completely
> stupid: we want our own event loop to run (eg, the Qt
> event loop), and once something arrives at stdin, call
> GNU readline to process whatever arrived.
>
> I already wrote the necessary changes and already put
> up some patch on the python issue tracker:
> http://bugs.python.org/issue22412
I'm sorry your patch got rejected--it looks like something you put a
lot of thought into! That said, reading over the thread, I agree with
the rationale and it seemed to come with a "for now" attached to it,
as in, it's not like it's a bad idea. And indeed Python's REPL event
loop has been controversial for a long time now (though to say it's
not needed is also incorrect at least on some major platforms...)
Relatedly, if you like horror stories, you should see the time I had
to reimplement raw_input and replace it in the builtins module since
it would fall over and *always* block if sys.stdin was replaced:
https://gist.github.com/embray/3dc1dcb0d264bce912fb
(Fortunately this issue is fixed on Python 3 at least.)
I agree that having something like your asyncio console in a
third-party library sounds interesting, and might also look nice as
part of IPython (though I defer to the IPython/Jupyter devs on that of
course ;)
Erik
More information about the IPython-dev
mailing list