From 8bafe241c8afaeebe0e0afb161f7a1e1a5e691be Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Fri, 11 Jul 2014 10:59:48 -0500 Subject: [PATCH 1/4] Close temp file to silence warning on python 3 --- lib/matplotlib/tests/test_animation.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/matplotlib/tests/test_animation.py b/lib/matplotlib/tests/test_animation.py index 9da8f81de6c3..29fc30250321 100644 --- a/lib/matplotlib/tests/test_animation.py +++ b/lib/matplotlib/tests/test_animation.py @@ -62,6 +62,8 @@ def animate(i): raise KnownFailureTest("There can be errors in the numpy " + "import stack, " + "see issues #1891 and #2679") + finally: + F.close() @cleanup From 63337277da533761102565455662c218981dc6eb Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Fri, 11 Jul 2014 12:23:50 -0500 Subject: [PATCH 2/4] Overload grab_frame to close temp files --- lib/matplotlib/animation.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/matplotlib/animation.py b/lib/matplotlib/animation.py index 354873b351c3..deea534b25b6 100644 --- a/lib/matplotlib/animation.py +++ b/lib/matplotlib/animation.py @@ -208,6 +208,7 @@ def grab_frame(self, **savefig_kwargs): # frame format and dpi. self.fig.savefig(self._frame_sink(), format=self.frame_format, dpi=self.dpi, **savefig_kwargs) + except RuntimeError: out, err = self._proc.communicate() verbose.report('MovieWriter -- Error ' @@ -326,6 +327,30 @@ def _frame_sink(self): # because it will no longer be referenced and will be gc-ed. return open(fname, 'wb') + def grab_frame(self, **savefig_kwargs): + ''' + Grab the image information from the figure and save as a movie frame. + All keyword arguments in savefig_kwargs are passed on to the 'savefig' + command that saves the figure. + ''' + #Overloaded to explicitly close temp file. + verbose.report('MovieWriter.grab_frame: Grabbing frame.', + level='debug') + try: + # Tell the figure to save its data to the sink, using the + # frame format and dpi. + myframesink = self._frame_sink() + self.fig.savefig(myframesink, format=self.frame_format, + dpi=self.dpi, **savefig_kwargs) + myframesink.close() + + except RuntimeError: + out, err = self._proc.communicate() + verbose.report('MovieWriter -- Error ' + 'running proc:\n%s\n%s' % (out, + err), level='helpful') + raise + def finish(self): # Call run here now that all frame grabbing is done. All temp files # are available to be assembled. From 24e69e0884fc025b9aafa7ee1b9d02844e9b13f6 Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Fri, 11 Jul 2014 15:26:15 -0500 Subject: [PATCH 3/4] Use communicate to make sure that pipes are probably closed in anim --- lib/matplotlib/animation.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/animation.py b/lib/matplotlib/animation.py index deea534b25b6..8ddf957d27a7 100644 --- a/lib/matplotlib/animation.py +++ b/lib/matplotlib/animation.py @@ -248,10 +248,11 @@ def isAvailable(cls): running the commandline tool. ''' try: - subprocess.Popen(cls.bin_path(), + p = subprocess.Popen(cls.bin_path(), shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + p.communicate() return True except OSError: return False From 52e5bafd7cbf6f8f284fca91bd8f3a68193341d3 Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Fri, 11 Jul 2014 15:29:36 -0500 Subject: [PATCH 4/4] Whitespace --- lib/matplotlib/animation.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/matplotlib/animation.py b/lib/matplotlib/animation.py index 8ddf957d27a7..f8cd5aeef5f0 100644 --- a/lib/matplotlib/animation.py +++ b/lib/matplotlib/animation.py @@ -208,7 +208,6 @@ def grab_frame(self, **savefig_kwargs): # frame format and dpi. self.fig.savefig(self._frame_sink(), format=self.frame_format, dpi=self.dpi, **savefig_kwargs) - except RuntimeError: out, err = self._proc.communicate() verbose.report('MovieWriter -- Error '