Skip to content

Commit

Permalink
Merge pull request matplotlib#27785 from tacaswell/fix/windows_pgf_sh…
Browse files Browse the repository at this point in the history
…utdown

FIX: be careful about communicating with subprocess
(cherry picked from commit c90234f)
  • Loading branch information
greglucas authored and QuLogic committed Feb 14, 2024
1 parent 240ff81 commit 7bf2554
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/matplotlib/backends/backend_pgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ def _setup_latex_process(self, *, expect_reply=True):
# Open LaTeX process for real work; register it for deletion. On
# Windows, we must ensure that the subprocess has quit before being
# able to delete the tmpdir in which it runs; in order to do so, we
# must first `kill()` it, and then `communicate()` with it.
# must first `kill()` it, and then `communicate()` with or `wait()` on
# it.
try:
self.latex = subprocess.Popen(
[mpl.rcParams["pgf.texsystem"], "-halt-on-error"],
Expand All @@ -324,7 +325,10 @@ def _setup_latex_process(self, *, expect_reply=True):

def finalize_latex(latex):
latex.kill()
latex.communicate()
try:
latex.communicate()
except RuntimeError:
latex.wait()

self._finalize_latex = weakref.finalize(
self, finalize_latex, self.latex)
Expand Down

0 comments on commit 7bf2554

Please sign in to comment.