Skip to content

Commit

Permalink
FIX: be careful about communicating with subprocess
Browse files Browse the repository at this point in the history
On windows on py312 we can not use `.communicate` during process shutdown
because it internally uses Python threads which can no longer be created during
interpreter shutdown.

Closes matplotlib#27437
  • Loading branch information
tacaswell committed Feb 13, 2024
1 parent 1defb57 commit 41bf7cc
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 @@ -257,7 +257,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 @@ -274,7 +275,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 41bf7cc

Please sign in to comment.