8000 Overload grab_frame to close temp files · matplotlib/matplotlib@6333727 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6333727

Browse files
committed
Overload grab_frame to close temp files
1 parent 8bafe24 commit 6333727

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

lib/matplotlib/animation.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ def grab_frame(self, **savefig_kwargs):
208208
# frame format and dpi.
209209
self.fig.savefig(self._frame_sink(), format=self.frame_format,
210210
dpi=self.dpi, **savefig_kwargs)
211+
211212
except RuntimeError:
212213
out, err = self._proc.communicate()
213214
verbose.report('MovieWriter -- Error '
@@ -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.

0 commit comments

Comments
 (0)
0