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

Skip to content

Commit afc464c

Browse files
committed
Merged revisions 6990 via svnmerge from
https://matplotlib.svn.sf.net/svnroot/matplotlib/branches/v0_98_5_maint ........ r6990 | mdboom | 2009-03-18 11:48:30 -0400 (Wed, 18 Mar 2009) | 2 lines Fix race condition in tempfile creation in PS backend. If two mpl processes try to create PS files with the same file name and the same time, they will use the same tempfile, and madness, crashing and burning will ensue. ........ svn path=/trunk/matplotlib/; revision=6991
1 parent 3fed025 commit afc464c

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

lib/matplotlib/backends/backend_ps.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def _fn_name(): return sys._getframe(1).f_code.co_name
1111
except ImportError:
1212
from md5 import md5 #Deprecated in 2.5
1313

14-
from tempfile import gettempdir
14+
from tempfile import mkstemp
1515
from cStringIO import StringIO
1616
from matplotlib import verbose, __version__, rcParams
1717
from matplotlib._pylab_helpers import Gcf
@@ -886,15 +886,15 @@ def _print_figure(self, outfile, format, dpi=72, facecolor='w', edgecolor='w',
886886
"""
887887
isEPSF = format == 'eps'
888888
passed_in_file_object = False
889+
fd, tmpfile = mkstemp()
889890
if is_string_like(outfile):
890891
title = outfile
891-
tmpfile = os.path.join(gettempdir(), md5(outfile).hexdigest())
892892
elif is_writable_file_like(outfile):
893893
title = None
894-
tmpfile = os.path.join(gettempdir(), md5(str(hash(outfile))).hexdigest())
895894
passed_in_file_object = True
896895
else:
897896
raise ValueError("outfile must be a path or a file-like object")
897+
os.close(fd)
898898
fh = file(tmpfile, 'w')
899899

900900
# find the appropriate papertype
@@ -1029,7 +1029,8 @@ def _print_figure_tex(self, outfile, format, dpi, facecolor, edgecolor,
10291029
title = outfile
10301030

10311031
# write to a temp file, we'll move it to outfile when done
1032-
tmpfile = os.path.join(gettempdir(), md5(outfile).hexdigest())
1032+
fd, tmpfile = mkstemp()
1033+
os.close(fd)
10331034
fh = file(tmpfile, 'w')
10341035

10351036
self.figure.dpi = 72 # ignore the dpi kwarg

0 commit comments

Comments
 (0)