From 437386b35bcecc362abc37f97ebac5c0b2dceebf Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sat, 10 Dec 2016 21:55:15 -0500 Subject: [PATCH] MNT: tweak MovieWriter.saving to be more cautious - always try to call `finish` even if an exception is raised. - return `self` so that with writer.saving(...) as mv: mv.grab_frame() works as expected. --- lib/matplotlib/animation.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/animation.py b/lib/matplotlib/animation.py index b4f1b77bb967..48d596fbc0ec 100644 --- a/lib/matplotlib/animation.py +++ b/lib/matplotlib/animation.py @@ -236,8 +236,10 @@ def saving(self, *args, **kw): ''' # This particular sequence is what contextlib.contextmanager wants self.setup(*args, **kw) - yield - self.finish() + try: + yield self + finally: + self.finish() def _run(self): # Uses subprocess to call the program for assembling frames into a