Skip to content

invalid command name "..._on_timer" in FuncAnimation for (too) small interval #8107

Closed

Description

@voxspox

To get a high frame rate for my animation I use a low value for 'interval' for 'FuncAnimation'. If interval is too low p.ex. 10, I get the following Exception, when (and only when) I close the window:

invalid command name "140613997300232_on_timer"
while executing
"140613997300232_on_timer"
("after" script)
Traceback (most recent call last):
File "./monitor.py", line 93, in
plt.show()
File "env/lib/python3.5/site-packages/matplotlib/pyplot.py", line 253, in show
return _show(*args, **kw)
File "env/lib/python3.5/site-packages/matplotlib/backend_bases.py", line 163, in call
manager.show()
File "env/lib/python3.5/site-packages/matplotlib/backends/backend_tkagg.py", line 610, in show
self.canvas.manager.window.attributes('-topmost', 1)
AttributeError: 'NoneType' object has no attribute 'attributes'

matplotlib==2.0.0

Activity

  1. dstansby commented on Feb 20, 2017

    @dstansby
    Member

    Thanks for the bug report! Could you possibly post a minimal example of code (including all the module imports) that triggers this error?

  2. tacaswell commented on Feb 20, 2017

    @tacaswell
    Member

    Looks like a race condition tearing down the window (because you closed it) and the timer being fired (only shows up at low interval because you have at catch a timer 'in flight' when you click the 'close' button).

  3. added this to the milestone on Feb 20, 2017
  4. anntzer commented on Feb 20, 2017

    @anntzer
    Contributor

    I can reproduce with examples/animation/simple_anim.py with an interval set to 1 and the tkagg backend.

    As a side note that example doesn't work at all in the gtk3agg backend:

    Traceback (most recent call last):
      File "/home/antony/src/extern/matplotlib/lib/matplotlib/backends/backend_gtk3agg.py", line 69, in on_draw_event
        buf, cairo.FORMAT_ARGB32, width, height)
    NotImplementedError: Surface.create_for_data: Not Implemented yet.
    
  5. QuLogic commented on Feb 21, 2017

    @QuLogic
    Member

    @anntzer You need cairocffi for Gtk3Agg + Python 3 to work; you should have got a warning about it.

  6. anntzer commented on Feb 21, 2017

    @anntzer
    Contributor

    Ah, yes, I didn't see the warning because it got immediately drowned out by the repeating (due to animation) error message regarding create_for_data.

    If it doesn't work without cairocffi, should it be an ImportError?

  7. modified the milestones: , on May 3, 2017
  8. modified the milestones: , on Oct 9, 2017
  9. Robomate commented on Feb 4, 2018

    @Robomate

    happens, when I close the matplotlib animation plot.

    invalid command name "140609567202440_on_timer"
        while executing
    "140609567202440_on_timer"
        ("after" script)
    
  10. richardsheridan commented on Aug 12, 2020

    @richardsheridan
    Contributor

    The ultimate cause of this bug was the destruction of the tk canvas occurring before the execution of _on_timer in the Tcl event queue while simultaneously failing to execute after_cancel (can't really explain that). The bug appears to be fixed on master, likely by #17802 or #17789. This issue should be closed if others can reproduce this, however, a new bug has appeared for the smallest values of interval, see #18236.

  11. modified the milestones: needs sorting, v3.4.0 on Aug 18, 2020
  12. ffernandoalves commented on Oct 31, 2020

    @ffernandoalves

    I get the same error when the blit parameter is True, for a large volume of data

  13. aravindpoolla07 commented on Mar 10, 2022

    @aravindpoolla07

    Hi, I got the same error. I am trying to plot real-time values in Tkinter which I obtained from Arduino sensor data. The plots work and everything is working but I get this error shown below. My sensor values contain floating-point values.

    Can someone tell me should I fix this issue or just leave it as everything is working fine?

    Forex like this
    [2.05
    1.74
    1.65
    1.6
    1.59
    1.59
    1.6
    1.59
    1.58
    1.58
    1.6]

    My error is

    invalid command name "1873019790016_on_timer"
    while executing
    "1873019790016_on_timer"
    ("after" script)
    invalid command name "1873007000832_on_timer"
    while executing
    "1873007000832_on_timer"
    ("after" script)

    My code looks like this

    `style.use('ggplot')
    fig = plt.figure(figsize=(15, 6), dpi=60)
    ax1 = fig.add_subplot(221)
    ax1.set_title("Analog Voltage ")
    ax1.set_xlabel("Time")
    ax1.set_ylabel(" Analog Voltage")
    ax1.set_ylim(-0.5, 5)
    line, = ax1.plot(analog_voltage, 'b')
    
    
    ax2 = fig.add_subplot(222)
    ax2.set_title("Voltage")
    ax2.set_xlabel("Time")
    ax2.set_ylabel(" Voltage")
    ax2.set_ylim(-0.5, 5)
    line1, = ax2.plot(Voltage, '-r')
    
    
    ax3 = fig.add_subplot(223)
    ax3.set_title("Current")
    ax3.set_xlabel("Time")
    ax3.set_ylabel(" Current mA")
    ax3.set_ylim(-0.5, 3)
    line2, = ax3.plot(Current, 'y')
    
    
    ax4 = fig.add_subplot(224)
    ax4.set_title("Temperature")
    ax4.set_xlabel("Time")
    ax4.set_ylabel(" Temperature °C")
    ax4.set_ylim(-10, 80)
    line3, = ax4.plot(Temperature, 'r') 
    

    Function to append values into the plot

    def animate(i):
    
      line.set_xdata(range(0, len(analog_voltage)))
      line.set_ydata(analog_voltage)
      
      line1.set_xdata(range0, len(Voltage)))
      line1.set_ydata(Voltage)
      
      line2.set_xdata(range(0, len(Current)))
      line2.set_ydata(Current)
      
      line3.set_xdata(range(0, len(Temperature)))
      line3.set_ydata(Temperature)
    
      ax1.set_xlim(0,i+1)
      ax2.set_xlim(0,i+1)
      ax3.set_xlim(0,i+1)
      ax4.set_xlim(0,i+1)
    
    #plotting the live data
    plotcanvas = FigureCanvasTkAgg(fig, root)
    plotcanvas.get_tk_widget().pack()
    ani = animation.FuncAnimation(fig, animate,interval=1000 ,blit=False)`
    
  14. tacaswell commented on Mar 10, 2022

    @tacaswell
    Member

    @aravindpoolla07 Can you please open a new issue?

  15. aravindpoolla07 commented on Mar 10, 2022

    @aravindpoolla07

    ok sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions