10000 backend_pgf does not delete temp directories on Windows, changes the current directory · Issue #1281 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
backend_pgf does not delete temp directories on Windows, changes the current directory #1281
Closed
@cgohlke

Description

@cgohlke

On Windows with mpl 1.2.0rc2, the following script successfully creates the figure but prints an error: could not delete tmp directory c:\users\...\temp\tmph2fo4m

import matplotlib
matplotlib.use('pgf')
from matplotlib import pyplot
pyplot.plot()
pyplot.savefig("test.pdf")

The backend_pgf fails to delete temporary directories because a latex process is started from the temporary directory. On Windows, directories and files can not be deleted while they are in use. The following code found in backend_pgf is also not thread safe:

tmpdir = tempfile.mkdtemp()
cwd = os.getcwd()
os.chdir(tmpdir)
...
self.print_pgf("figure.pgf")  # starts LatexManager in tmpdir
...
os.chdir(cwd)
shutil.rmtree(tmpdir)  # fails because LatexManager is still open in tmpdir

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0