Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aabfd09

Browse files
committed
Merge pull request matplotlib#3215 from jenshnielsen/close_files
Close files in animation to silence some warning in the test suite on python3
2 parents eb48031 + 52e5baf commit aabfd09

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/matplotlib/animation.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,11 @@ def isAvailable(cls):
247247
running the commandline tool.
248248
'''
249249
try:
250-
subprocess.Popen(cls.bin_path(),
250+
p = subprocess.Popen(cls.bin_path(),
251251
shell=False,
252252
stdout=subprocess.PIPE,
253253
stderr=subprocess.PIPE)
254+
p.communicate()
254255
return True
255256
except OSError:
256257
return False
@@ -326,6 +327,30 @@ def _frame_sink(self):
326327
# because it will no longer be referenced and will be gc-ed.
327328
return open(fname, 'wb')
328329

330+
def grab_frame(self, **savefig_kwargs):
331+
'''
332+
Grab the image information from the figure and save as a movie frame.
333+
All keyword arguments in savefig_kwargs are passed on to the 'savefig'
334+
command that saves the figure.
335+
'''
336+
#Overloaded to explicitly close temp file.
337+
verbose.report('MovieWriter.grab_frame: Grabbing frame.',
338+
level='debug')
339+
try:
340+
# Tell the figure to save its data to the sink, using the
341+
# frame format and dpi.
342+
myframesink = self._frame_sink()
343+
self.fig.savefig(myframesink, format=self.frame_format,
344+
dpi=self.dpi, **savefig_kwargs)
345+
myframesink.close()
346+
347+
except RuntimeError:
348+
out, err = self._proc.communicate()
349+
verbose.report('MovieWriter -- Error '
350+
'running proc:\n%s\n%s' % (out,
351+
err), level='helpful')
352+
raise
353+
329354
def finish(self):
330355
# Call run here now that all frame grabbing is done. All temp files
331356
# are available to be assembled.

lib/matplotlib/tests/test_animation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def animate(i):
6262
raise KnownFailureTest("There can be errors in the numpy " +
6363
"import stack, " +
6464
"see issues #1891 and #2679")
65+
finally:
66+
F.close()
6567

6668

6769
@cleanup

0 commit comments

Comments
 (0)