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....@gmail.com> wrote: > From: Brian Granger <ellisonbg....@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" <mjldeh...@yahoo.com> > Cc: "Robert Kern" <rk...@enthought.com>, enthought-...@enthought.com, > "matplotlib development list" <matplotlib-devel@lists.sourceforge.net>, > "IPython Development list" <ipython-...@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....@gmail.com> wrote: > > > > > From: Brian Granger <ellisonbg....@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" <rk...@enthought.com> > > > Cc: enthought-...@enthought.com, > "matplotlib development list" <matplotlib-devel@lists.sourceforge.net>, > "IPython Development list" <ipython-...@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-...@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@lists.sourceforge.net > > > https://lists.sourceforge.net/lists/listinfo/matplotlib-devel > > > > > > > > > > > > > ------------------------------------------------------------------------------ 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 _______________________________________________ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel