Cannot delete matplotlib.animation.FuncAnimation objects

不问归期 提交于 2019-12-04 17:39:13

To sort out what is going on here involves going down into the guts of how the animation module and two callback registries work.

When you create the Animation object it registers a callback into the mpl callback registry on the draw_event so that after the first time that the canvas is drawn after the Animation object is created the timed animation sets it self up (by registering a callback into a timer object) and a callback into the mpl callback registry on the close_event to tear the timer down.

The mpl callback registry does a bunch of introspection of the callables that come in and reconstructs bound methods into a weakref to the object an the relevant function. Thus, if you you create an animation object but don't keep a ref to it, it's refcount will go to zero, the weakref to it in the mpl callback registry will fail, and the animation will never start.

The way that the timer works it Qt is that you register a callable which is added to a list (I am getting this from your diagram at the bottom) so it is holding a hard reference to the Animation object, thus removing the ref you hold in your object is not enough to drive the ref count to zero. In the case of timers callbacks this is probably a feature, not a bug.

By artifacts, I now understand to mean you are creating a second Animation object and what you get is both of them running in parallel (which I am not sure what I expect to happen there).

To stop a running Animation and remove it from the timer's callback list use the private method (which should be public) _stop which is what responsible for the tear down (and is the method registered on close_event).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!