[IPython-dev] IPython inputhook, higher rate?

Erik Bray erik.m.bray at gmail.com
Thu Sep 25 11:17:00 EDT 2014


On Thu, Sep 25, 2014 at 2:31 AM, Gustavo Goretkin
<gustavo.goretkin at gmail.com> wrote:
> I'm looking to investigate this but I'm confused about some important things
>
> CPython calls the inputhook at 10Hz according to [1]. You can verify this
> with [2], so my issue isn't related to SDL or pygame. It's just that the
> callback gets called infrequently.
>
> How then am I able to manipulate my matplotlib window and type more than 10
> characters a second into the interpreter prompt? According to import
> threading; threading.enumerate(), there are no threads aside from the
> "_MainThread" and "HistorySavingThread", so I think some threads are being
> setup and run from the gui libraries (like wx). I guess I do not understand
> what is meant in [3].

Good questions-- speaking of matplotlib as an example, on my system
when I run Python in interactive mode the default backend for
matplotlib is TKAgg, and hence is using TK for the graphical
display/event handling.  So the place to look is the tkinter module's
own InputHook handler.

In short, it basically sets up its own select() loop that processing
TCL events (each followed by a sleep, adjustable by
_tkinter.setbusywaitinterval --the default is 20 ms) which runs until
input is ready on stdin (at which point it returns control to Python).
This is separate from the normal main event loop in that it *can*
return control without quitting.

If you look, for example, at IPython's inputhook handler for pyglet
[1] you can see it does something pretty similar to what I just
described.  So something similar is needed that will be compatible
with pygame -- or pysdl more generally.

Hope that helps!

Erik

[1] https://github.com/ipython/ipython/blob/master/IPython/lib/inputhookpyglet.py





> On Tue, Sep 9, 2014 at 1:07 PM, Fernando Perez <fperez.net at gmail.com> wrote:
>>
>> On Tue, Sep 9, 2014 at 10:03 AM, Erik Bray <erik.m.bray at gmail.com> wrote:
>>>
>>> My guess is that an inputhook handler for SDL similar to the pyglet
>>> inputhook might be necessary:
>>>
>>>
>>> https://github.com/ipython/ipython/blob/825f3e480e9d9e4032abab7bc72e5cd086cc3e89/IPython/lib/inputhookpyglet.py
>>
>>
>> Yup, good guess.  I suspect the solution is along those lines too.
>>
>>>
>>> I don't have any more time too look into it right now though.
>>
>>
>> Sadly, most of us in the core team are in the same boat. If someone can
>> put together a well-tested PR that solves the problem for them, we can
>> probably merge it relatively quickly. These things are typically a small
>> amount of code, but they require patience to get right and lots of live,
>> interactive testing. We can't do that right now on this topic, but a clean
>> PR where someone has done all that leg work would likely not be too hard to
>> merge.
>>
>> Cheers,
>>
>> f
>>
>>
>> --
>> Fernando Perez (@fperez_org; http://fperez.org)
>> fperez.net-at-gmail: mailing lists only (I ignore this when swamped!)
>> fernando.perez-at-berkeley: contact me here for any direct mail
>>
>> _______________________________________________
>> IPython-dev mailing list
>> IPython-dev at scipy.org
>> http://mail.scipy.org/mailman/listinfo/ipython-dev
>>
>
>
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>



More information about the IPython-dev mailing list