@@ -349,21 +349,16 @@ def grab_frame(self, **savefig_kwargs):
349349 # All frames must have the same size to save the movie correctly.
350350 self .fig .set_size_inches (self ._w , self ._h )
351351 # Save the figure data to the sink, using the frame format and dpi.
352- self .fig .savefig (self ._frame_sink () , format = self .frame_format ,
352+ self .fig .savefig (self ._proc . stdin , format = self .frame_format ,
353353 dpi = self .dpi , ** savefig_kwargs )
354354
355- def _frame_sink (self ):
356- """Return the place to which frames should be written."""
357- return self ._proc .stdin
358-
359355 def _args (self ):
360356 """Assemble list of encoder-specific command-line arguments."""
361357 return NotImplementedError ("args needs to be implemented by subclass." )
362358
363359 def _cleanup (self ): # Inline to finish() once cleanup() is removed.
364360 """Clean-up and collect the process used to write the movie file."""
365361 out , err = self ._proc .communicate ()
366- self ._frame_sink ().close ()
367362 # Use the encoding/errors that universal_newlines would use.
368363 out = TextIOWrapper (BytesIO (out )).read ()
369364 err = TextIOWrapper (BytesIO (err )).read ()
@@ -483,30 +478,18 @@ def _base_temp_name(self):
483478 # for extension and the prefix.
484479 return self .fname_format_str % (self .temp_prefix , self .frame_format )
485480
486- def _frame_sink (self ):
487- # Creates a filename for saving using the basename and the current
488- # counter.
489- path = Path (self ._base_temp_name () % self ._frame_counter )
490-
491- # Save the filename so we can delete it later if necessary
492- self ._temp_paths .append (path )
493- _log .debug ('FileMovieWriter.frame_sink: saving frame %d to path=%s' ,
494- self ._frame_counter , path )
495- self ._frame_counter += 1 # Ensures each created name is 'unique'
496-
497- # This file returned here will be closed once it's used by savefig()
498- # because it will no longer be referenced and will be gc-ed.
499- return open (path , 'wb' )
500-
501481 def grab_frame (self , ** savefig_kwargs ):
502482 # docstring inherited
503483 # Overloaded to explicitly close temp file.
504- _log .debug ('MovieWriter.grab_frame: Grabbing frame.' )
505- # Tell the figure to save its data to the sink, using the
506- # frame format and dpi.
507- with self ._frame_sink () as myframesink :
508- self .fig .savefig (myframesink , format = self .frame_format ,
509- dpi = self .dpi , ** savefig_kwargs )
484+ # Creates a filename for saving using basename and counter.
485+ path = Path (self ._base_temp_name () % self ._frame_counter )
486+ self ._temp_paths .append (path ) # Record the filename for later cleanup.
487+ self ._frame_counter += 1 # Ensures each created name is unique.
488+ _log .debug ('FileMovieWriter.grab_frame: Grabbing frame %d to path=%s' ,
489+ self ._frame_counter , path )
490+ with open (path , 'wb' ) as sink : # Save figure to the sink.
491+ self .fig .savefig (sink , format = self .frame_format , dpi = self .dpi ,
492+ ** savefig_kwargs )
510493
511494 def finish (self ):
512495 # Call run here now that all frame grabbing is done. All temp files
0 commit comments