On Fri, Jul 17, 2009 at 3:57 PM, Ville M. Vainio<vivai...@gmail.com> wrote:
> On Sat, Jul 18, 2009 at 12:54 AM, Brian Granger<ellisonbg....@gmail.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.
     """
     import wx
+    from timeit import default_timer as clock
     app = wx.GetApp()
     if app is not None:
         assert wx.Thread_IsMain()

         evtloop = wx.EventLoop()
         ea = wx.EventLoopActivator(evtloop)
+        t = clock()
         while not stdin_ready():
             while evtloop.Pending():
+                t = clock()
                 evtloop.Dispatch()
             app.ProcessIdle()
-            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
+                time.sleep(0.05)
+            else:
+                # input is happening, either wx (e.g. mouse) or keyboard, so
+                # sleep only very little
+                time.sleep(0.001)
         del ea
     return 0



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.

Ondrej

------------------------------------------------------------------------------
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

Reply via email to