8000 backend_pgf: improve handling of temporary directories by pwuertz · Pull Request #1286 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

backend_pgf: improve handling of temporary directories #1286

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 4 commits into from
Oct 2, 2012
Merged
Changes from 1 commit
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
10000
Diff view
Diff view
Prev Previous commit
Next Next commit
backend_pgf: track remaining tmpdirs and try to delete them atexit
  • Loading branch information
pwuertz committed Oct 2, 2012
commit c810d471a5bb0440131d781a72c7eb94eb4ea6b5
26 changes: 23 additions & 3 deletions lib/matplotlib/backends/backend_pgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,22 @@ def new_figure_manager_given_figure(num, figure):
return manager


class TmpDirCleaner:
remaining_tmpdirs = set()

@staticmethod
def add(tmpdir):
TmpDirCleaner.remaining_tmpdirs.add(tmpdir)

@staticmethod
def cleanup_remaining_tmpdirs():
for tmpdir in TmpDirCleaner.remaining_tmpdirs:
try:
shutil.rmtree(tmpdir)
except:
sys.stderr.write("error deleting tmp directory %s\n" % tmpdir)


class FigureCanvasPgf(FigureCanvasBase):
filetypes = {"pgf": "LaTeX PGF picture",
"pdf": "LaTeX compiled PGF picture",
Expand Down Expand Up @@ -798,7 +814,7 @@ def _print_pdf_to_fh(self, fh):
try:
shutil.rmtree(tmpdir)
except:
sys.stderr.write("error deleting tmp directory %s\n" % tmpdir)
TmpDirCleaner.add(tmpdir)

def print_pdf(self, fname_or_fh, *args, **kwargs):
"""
Expand Down Expand Up @@ -831,7 +847,7 @@ def _print_png_to_fh(self, fh):
try:
shutil.rmtree(tmpdir)
except:
sys.stderr.write("error deleting tmp directory %s\n" % tmpdir)
TmpDirCleaner.add(tmpdir)

def print_png(self, fn 5E58 ame_or_fh, *args, **kwargs):
"""
Expand Down Expand Up @@ -904,4 +920,8 @@ def __init__(self, *args):

FigureManager = FigureManagerPgf

atexit.register(LatexManager._cleanup_remaining_instances)
def _cleanup_all():
LatexManager._cleanup_remaining_instances()
TmpDirCleaner.cleanup_remaining_tmpdirs()

atexit.register(_cleanup_all)
0