Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Cannot stop/garbage collect an animation #16853

Open
@nbud

Description

Bug report

Bug summary

The animation documentation states that the reference to the Animation object must be held to prevent the animation from stopping due to garbage collection. I cannot reproduce this. Also, I do not find any way to stop the animation. I presume the Animation object is held somewhere, and this is undocumented.

The bigger picture for me: I pass as the frames argument of FuncAnimation a generator which streams data from a device via a socket. When the generator is garbage collected, the socket is deleted and the device is free to take new connections. Because I cannot garbage collect the Animation object, I cannot garbe collec the socket instrument either and the device hangs.

Related #16221

Code for reproduction

Adapted from https://matplotlib.org/3.1.3/api/animation_api.html :

import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import gc
fig, ax = plt.subplots()
xdata, ydata = [], []
ln, = plt.plot([], [], 'ro')
def init():
 ax.set_xlim(0, 2*np.pi)
 ax.set_ylim(-1, 1)
 return ln,
def update(frame):
 xdata.append(frame)
 ydata.append(np.sin(frame))
 ln.set_data(xdata, ydata)
 return ln,
FuncAnimation(fig, update, frames=np.linspace(0, 2*np.pi, 128),
 init_func=init, blit=True)
gc.collect() # force garbage collection
plt.show()

Actual outcome

The animation works.

Expected outcome

The animation should not work, as described in the doc.

Matplotlib version

  • Operating system: Windows 10
  • Matplotlib version: 3.1.3
  • Matplotlib backend (print(matplotlib.get_backend())): issue affects at least Qt5Agg and Tk5Agg
  • Python version: 3.7.6
  • Jupyter version (if applicable):
  • Other libraries: Anaconda 2020.02

Issue was reproducted in a Python console and in Spyder 4

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /