[IPython-dev] [Enthought-Dev] [matplotlib-devel] Ctypes based prototype of PyOS_InputHook for wx 2.8 and 2.9
Fri Jul 17 18:15:20 CDT 2009
On Fri, Jul 17, 2009 at 3:57 PM, Ville M. Vainio<firstname.lastname@example.org> wrote:
> On Sat, Jul 18, 2009 at 12:54 AM, Brian Granger<email@example.com> wrote:
>> best. Bottom line = we are into a position of compromise because of wx.
>> The good news is that I think we can offer users a very flexible way of
>> tuning all these things.
> Perhaps adaptive autotuning algorithm could help your case; if stdin
> came in rapidly, poll again very soon, otherwise adjust the delay.
The following patch implements this in the #3 approach:
$ diff -Naur /home/ondrej/Desktop/inputhook.py inputhook.py
--- /home/ondrej/Desktop/inputhook.py 2009-07-17 14:09:34.000000000 -0600
+++ inputhook.py 2009-07-17 17:12:37.000000000 -0600
@@ -110,17 +110,26 @@
This sleep time should be tuned though for best performance.
+ from timeit import default_timer as clock
app = wx.GetApp()
if app is not None:
evtloop = wx.EventLoop()
ea = wx.EventLoopActivator(evtloop)
+ t = clock()
while not stdin_ready():
+ t = clock()
- time.sleep(0.01) # Change this to tune performance
+ if clock() - t > 0.1:
+ # no input is happening, we can sleep as much as we want
+ # input is happening, either wx (e.g. mouse) or keyboard, so
+ # sleep only very little
Now if no input is happening, the "sleep(0.05)" version is running,
thus it has very low CPU usage. If however some input is happening
(either matplotlib, or ipython), then we just sleep(0.001), maybe we
don't have to sleep at all, I am not sure about this.
In any case, this should fix Gael's objection.
More information about the IPython-dev