Skip to content

Commit

Permalink
Merge pull request matplotlib#5249 from pwuertz/fix_5144
Browse files Browse the repository at this point in the history
Keep references to modules required in pgf LatexManager destructor
  • Loading branch information
mdboom committed Dec 2, 2015
1 parent 1f8b7f6 commit a561593
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/matplotlib/backends/backend_pgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,11 @@ def _expect_prompt(self):
return self._expect("\n*")

def __init__(self):
# store references for __del__
self._os_path = os.path
self._shutil = shutil
self._debug = rcParams.get("pgf.debug", False)

# create a tmp directory for running latex, remember to cleanup
self.tmpdir = tempfile.mkdtemp(prefix="mpl_pgf_lm_")
LatexManager._unclean_instances.add(self)
Expand Down Expand Up @@ -346,7 +351,7 @@ def __init__(self):
self.str_cache = {}

def _cleanup(self):
if not os.path.isdir(self.tmpdir):
if not self._os_path.isdir(self.tmpdir):
return
try:
self.latex.communicate()
Expand All @@ -355,13 +360,13 @@ def _cleanup(self):
except:
pass
try:
shutil.rmtree(self.tmpdir)
self._shutil.rmtree(self.tmpdir)
LatexManager._unclean_instances.discard(self)
except:
sys.stderr.write("error deleting tmp directory %s\n" % self.tmpdir)

def __del__(self):
if rcParams.get("pgf.debug", False):
if self._debug:
print("deleting LatexManager")
self._cleanup()

Expand Down

0 comments on commit a561593

Please sign in to comment.