Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Avoid need to lock in dvi generation, to avoid deadlocks. #17839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions lib/matplotlib/texmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from pathlib import Path
import re
import subprocess
from tempfile import TemporaryDirectory

import numpy as np

Expand Down Expand Up @@ -269,12 +270,12 @@ def make_tex_preview(self, tex, fontsize):

return texfile

def _run_checked_subprocess(self, command, tex):
def _run_checked_subprocess(self, command, tex, *, cwd=None):
_log.debug(cbook._pformat_subprocess(command))
try:
report = subprocess.check_output(command,
cwd=self.texcache,
stderr=subprocess.STDOUT)
report = subprocess.check_output(
command, cwd=cwd if cwd is not None else self.texcache,
stderr=subprocess.STDOUT)
except FileNotFoundError as exc:
raise RuntimeError(
'Failed to process string with tex because {} could not be '
Expand Down Expand Up @@ -305,17 +306,16 @@ def make_dvi(self, tex, fontsize):
dvifile = '%s.dvi' % basefile
if not os.path.exists(dvifile):
texfile = self.make_tex(tex, fontsize)
with cbook._lock_path(texfile):
# Generate the dvi in a temporary directory to avoid race
# conditions e.g. if multiple processes try to process the same tex
# string at the same time. Having tmpdir be a subdirectory of the
# final output dir ensures that they are on the same filesystem,
# and thus replace() works atomically.
with TemporaryDirectory(dir=Path(dvifile).parent) as tmpdir:
self._run_checked_subprocess(
["latex", "-interaction=nonstopmode", "--halt-on-error",
texfile], tex)
for fname in glob.glob(basefile + '*'):
if not fname.endswith(('dvi', 'tex')):
try:
os.remove(fname)
except OSError:
pass

texfile], tex, cwd=tmpdir)
(Path(tmpdir) / Path(dvifile).name).replace(dvifile)
return dvifile

@cbook.deprecated("3.3")
Expand Down