@@ -252,6 +252,8 @@ def _cleanup_remaining_instances():
252252 latex_manager ._cleanup ()
253253
254254 def _stdin_writeln (self , s ):
255+ if self .latex is None :
256+ self ._setup_latex_process ()
255257 self .latex_stdin_utf8 .write (s )
256258 self .latex_stdin_utf8 .write ("\n " )
257259 self .latex_stdin_utf8 .flush ()
@@ -265,6 +267,8 @@ def _expect(self, s):
265267 if buf [- len (exp ):] == exp :
266268 break
267269 if not len (b ):
270+ self .latex .kill ()
271+ self .latex = None
268272 raise LatexError ("LaTeX process halted" , buf .decode ("utf8" ))
269273 return buf .decode ("utf8" )
270274
@@ -301,6 +305,10 @@ def __init__(self):
301305 raise LatexError ("LaTeX returned an error, probably missing font "
302306 "or error in preamble:\n %s" % stdout )
303307
308+ self .latex = None # Will be set up on first use.
309+ self .str_cache = {} # cache for strings already processed
310+
311+ def _setup_latex_process (self ):
304312 # open LaTeX process for real work
305313 latex = subprocess .Popen ([self .texcommand , "-halt-on-error" ],
306314 stdin = subprocess .PIPE , stdout = subprocess .PIPE ,
@@ -313,9 +321,6 @@ def __init__(self):
313321 self ._expect ("*pgf_backend_query_start" )
314322 self ._expect_prompt ()
315323
316- # cache for strings already processed
317- self .str_cache = {}
318-
319324 def _cleanup (self ):
320325 if not self ._os_path .isdir (self .tmpdir ):
321326 return
@@ -427,10 +432,10 @@ def __init__(self, figure, fh, dummy=False):
427432 else :
428433 # if fh does not belong to a filename, deactivate draw_image
429434 if not hasattr (fh , 'name' ) or not os .path .exists (fh .name ):
430- cbook . _warn_external ( "streamed pgf-code does not support "
431- "raster graphics, consider using the "
432- "pgf-to-pdf option" , UserWarning )
433- self . __dict__ [ "draw_image" ] = lambda * args , ** kwargs : None
435+ self . __dict__ [ "draw_image" ] = \
436+ lambda * args , ** kwargs : cbook . _warn_external (
437+ "streamed pgf-code does not support raster graphics, "
438+ "consider using the pgf-to-pdf option" )
434439
435440 @cbook .deprecated ("3.2" )
436441 @property
0 commit comments