[IPython-dev] [matplotlib-devel] [Enthought-Dev] Ctypes based prototype of PyOS_InputHook for wx 2.8 and 2.9

Brian Granger ellisonbg.net at gmail.com
Fri Jul 17 15:48:33 EDT 2009


Michiel,

Thanks for the ideas.  I have implemented both of the approaches you
describe and I am attaching a file that has all 3 approaches.  At this
point, all 3 approaches work on OS X, Python 2.5 with wx 2.8/2.9.  What I
most need to to find strenuous test cases that can probe which of these has
the best performance?  Robert, could you run the Chaco test again with
approaches 2 and 3 and try tuning the parameters (see the docstrings)?

Cheers,

Brian

On Thu, Jul 16, 2009 at 11:32 PM, Michiel de Hoon <mjldehoon at yahoo.com>wrote:

>
> Without monitoring stdin, you could do the following:
>
> while True:
>    run the event loop for a specified duration (say, 0.1 seconds)
>    check for input on stdin; if there is any: break
>
> But you can only do this if wx has such a time-out capability. If not, you
> can do the following:
>
> while True:
>    handle all accumulated events
>    check for input on stdin; if there is any: break
>    sleep for 0.1 seconds
>
> The sleep is important, otherwise the CPU is busy 100% of the time, which
> will drain your battery.
>
> This loop is essentially what you are doing in your current code, except
> that you're using Python/readline for the repeated calls into the hook
> function. It's better to have this loop explicitly inside your hook
> function, because of the variation in PyOS_InputHook behavior between
> different versions of Python/readline.
>
> --Michiel
>
> --- On Fri, 7/17/09, Brian Granger <ellisonbg.net at gmail.com> wrote:
>
> > From: Brian Granger <ellisonbg.net at gmail.com>
> > Subject: Re: [matplotlib-devel] [IPython-dev] [Enthought-Dev] Ctypes
> based  prototype of PyOS_InputHook for wx 2.8 and 2.9
> > To: "Michiel de Hoon" <mjldehoon at yahoo.com>
> > Cc: "Robert Kern" <rkern at enthought.com>, enthought-dev at enthought.com,
> "matplotlib development list" <matplotlib-devel at lists.sourceforge.net>,
> "IPython Development list" <ipython-dev at scipy.org>
> > Date: Friday, July 17, 2009, 12:59 AM
> > Michiel,
> >
> > Thanks for the reply, this will help us to find a better
> > approach.  According to one of the wx devs, Robin Dunn, wx
> > currently does not have the ability to monitor stdin in its
> > even loop without polling.  I guess there is a GSoC project
> > to add this capability, but it is not there yet.  Any
> > thoughts on how this could be done without monitoring
> > stdin.  I will give the polling stdin approach a try
> > though.
> >
> >
> > Cheers,
> >
> > Brian
> >
> >
> >
> >
> > The chunkiness probably comes from the fact that
> > inputhook_wx is called repeatedly. This is different from
> > how PyOS_InputHook is being used in Tkinter, PyGTK, and the
> > Mac OS X backend.
> >
> >
> >
> > Schematically, this is how the Tkinter/PyGTK/MacOSX event
> > loops work:
> >
> >
> >
> > 1) PyOS_InputHook is called when Python is waiting for the
> > user to type in the next Python command.
> >
> >
> >
> > 2) The hook function sets up the event loop such that stdin
> > is being monitored while the event loop is running.
> >
> >
> >
> > 3) The hook function then starts the event loop.
> >
> >
> >
> > 4) When input is available on stdin, the hook function
> > exits the event loop, and returns.
> >
> >
> >
> > This is how the proposed Wx event loop currently works:
> >
> >
> >
> > 1) PyOS_InputHook is called when Python is waiting for the
> > user to type in the next Python command.
> >
> >
> >
> > 2) The hook function processes whatever events are
> > available at the time.
> >
> >
> >
> > 3) The hook function returns.
> >
> >
> >
> > 4) If still no input is available on stdin, Python calls
> > the hook function again via PyOS_InputHook after a timeout.
> >
> >
> >
> > I believe the timeout is 0.1 seconds by default. However,
> > Python may not call PyOS_InputHook repeatedly at all; this
> > depends on which Python version is being used, and the
> > version of the readline library. In some configurations
> > (particularly on Windows), PyOS_InputHook is called only
> > once, so wx will freeze between Python commands.
> >
> >
> >
> >
> > I am not familiar with wx, but there hopefully there is
> > some way to monitor stdin while the event loop is running?
> >
> >
> >
> > --Michiel.
> >
> >
> >
> >
> >
> > --- On Thu, 7/16/09, Brian Granger <ellisonbg.net at gmail.com> wrote:
> >
> >
> >
> > > From: Brian Granger <ellisonbg.net at gmail.com>
> >
> > > Subject: Re: [matplotlib-devel] [IPython-dev]
> > [Enthought-Dev] Ctypes based prototype of PyOS_InputHook for
> > wx 2.8 and 2.9
> >
> > > To: "Robert Kern" <rkern at enthought.com>
> >
> > > Cc: enthought-dev at enthought.com,
> > "matplotlib development list" <matplotlib-devel at lists.sourceforge.net>,
> > "IPython Development list" <ipython-dev at scipy.org>
> >
> >
> > > Date: Thursday, July 16, 2009, 6:57 PM
> >
> > > Robert,
> >
> > >
> >
> > > Thanks for testing this so quickly.  Performance is
> > one of
> >
> > > the big issues that I am concerned about.  I will
> > work on a
> >
> > > Cython based version to see if that solves the
> > problem.
> >
> > >
> >
> > > Cheers,
> >
> > >
> >
> > > Brian
> >
> > >
> >
> > >
> >
> > >
> >
> > >
> >
> > > Works for me with wx 2.8.8.1 on OS X 10.5 and
> >
> > > Chaco. Pan and zoom
> >
> > >
> >
> > > interactions are substantially chunky, though. I do
> > not see
> >
> > > such
> >
> > >
> >
> > > chunkiness with -wthread. It would be worth exploring
> > a
> >
> > > Cython
> >
> > >
> >
> > > alternative to see if it is just ctypes and general
> > Python
> >
> > > overhead to
> >
> > >
> >
> > > blame.
> >
> > >
> >
> > >
> >
> > >
> >
> > > --
> >
> > >
> >
> > > Robert Kern
> >
> > >
> >
> > >
> >
> > >
> >
> > > "I have come to believe that the whole world is
> > an
> >
> > > enigma, a harmless
> >
> > >
> >
> > > enigma that is made terrible by our own mad attempt
> > to
> >
> > > interpret it as
> >
> > >
> >
> > > though it had an underlying truth."
> >
> > >
> >
> > >   -- Umberto Eco
> >
> > >
> >
> > > _______________________________________________
> >
> > >
> >
> > > IPython-dev mailing list
> >
> > >
> >
> > > IPython-dev at scipy.org
> >
> > >
> >
> > > http://mail.scipy.org/mailman/listinfo/ipython-dev
> >
> > >
> >
> > >
> >
> > >
> >
> > >
> >
> > > -----Inline Attachment Follows-----
> >
> > >
> >
> > >
> >
> ------------------------------------------------------------------------------
> >
> > > Enter the BlackBerry Developer Challenge
> >
> > > This is your chance to win up to $100,000 in prizes!
> > For a
> >
> > > limited time,
> >
> > > vendors submitting new applications to BlackBerry App
> >
> > > World(TM) will have
> >
> > > the opportunity to enter the BlackBerry Developer
> >
> > > Challenge. See full prize
> >
> > > details at: http://p.sf.net/sfu/Challenge
> >
> > > -----Inline Attachment Follows-----
> >
> > >
> >
> > > _______________________________________________
> >
> > > Matplotlib-devel mailing list
> >
> > > Matplotlib-devel at lists.sourceforge.net
> >
> > > https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
> >
> > >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20090717/b3e038d3/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: inputhook.py
Type: application/octet-stream
Size: 5683 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20090717/b3e038d3/attachment.obj>


More information about the IPython-dev mailing list