@@ -252,6 +252,8 @@ def _cleanup_remaining_instances():
252
252
latex_manager ._cleanup ()
253
253
254
254
def _stdin_writeln (self , s ):
255
+ if self .latex is None :
256
+ self ._setup_latex_process ()
255
257
self .latex_stdin_utf8 .write (s )
256
258
self .latex_stdin_utf8 .write ("\n " )
257
259
self .latex_stdin_utf8 .flush ()
@@ -265,7 +267,9 @@ def _expect(self, s):
265
267
if buf [- len (exp ):] == exp :
266
268
break
267
269
if not len (b ):
268
- raise LatexError ("LaTeX process halted" , buf .decode ("utf8" ))
270
+ self .latex .kill ()
271
+ self .latex = None
272
+ raise LatexError ("LaTeX process halted" , buf .decode ("utf-8" ))
269
273
return buf .decode ("utf8" )
270
274
271
275
def _expect_prompt (self ):
@@ -301,6 +305,10 @@ def __init__(self):
301
305
raise LatexError ("LaTeX returned an error, probably missing font "
302
306
"or error in preamble:\n %s" % stdout )
303
307
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 ):
304
312
# open LaTeX process for real work
305
313
latex = subprocess .Popen ([self .texcommand , "-halt-on-error" ],
306
314
stdin = subprocess .PIPE , stdout = subprocess .PIPE ,
@@ -313,9 +321,6 @@ def __init__(self):
313
321
self ._expect ("*pgf_backend_query_start" )
314
322
self ._expect_prompt ()
315
323
316
- # cache for strings already processed
317
- self .str_cache = {}
318
-
319
324
def _cleanup (self ):
320
325
if not self ._os_path .isdir (self .tmpdir ):
321
326
return
@@ -427,10 +432,10 @@ def __init__(self, figure, fh, dummy=False):
427
432
else :
428
433
# if fh does not belong to a filename, deactivate draw_image
429
434
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" )
434
439
435
440
@cbook .deprecated ("3.2" )
436
441
@property
0 commit comments