-
-
Notifications
You must be signed in to change notification settings - Fork 8k
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