[timer] How it works?

Hello everyone,

I don't understand how works TimerBase.

From matplotlib import backend_bases

def write(x):
     print x

backend_bases.TimerBase._timer_start
backend_bases.TimerBase(1000,write(2))

It returns only "2" one time. Why it doesn't return 2 every second?

Thx in advance,

Fabien

Hello everyone,

I don't understand how works TimerBase.

>From matplotlib import backend_bases

def write(x):
print x

backend_bases.TimerBase._timer_start
backend_bases.TimerBase(1000,write(2))

TimerBase is a do-nothing skeleton class that provides the common
infrastructure for other backends to implement a timer that works with
them (just like the rest of backend_bases). For example, the gtk
backend uses this as a starting point for its own timer class. You
really shouldn't be instantiating TimerBase yourself as it won't do
anything.

It returns only "2" one time. Why it doesn't return 2 every second?

The only reason you actually see anything at all is because you call
write yourself when you do:

write(2)

The timer never actually does anything. The proper call is to separate
the function and its arguments, since as the docs say, it takes a
"list of (func, args) tuples that will be
called upon timer events":

TimerBase(1000, [(write, 2)])

However, the proper way to create a timer, which will intergrate
properly with the figure event loop, is shown in the example:

http://matplotlib.sourceforge.net/examples/event_handling/timers.html

In your case:

timer = fig.canvas.new_timer(interval=1000)
timer.add_callback(write, 2)
timer.start()

Ryan

···

On Tue, Nov 29, 2011 at 4:16 AM, Fabien Lafont <lafont.fabien@...287...> wrote:

--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma