Revision: 6990
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6990&view=rev
Author:   mdboom
Date:     2009-03-18 15:48:30 +0000 (Wed, 18 Mar 2009)

Log Message:
-----------
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.

Modified Paths:
--------------
    branches/v0_98_5_maint/lib/matplotlib/backends/backend_ps.py

Modified: branches/v0_98_5_maint/lib/matplotlib/backends/backend_ps.py
===================================================================
--- branches/v0_98_5_maint/lib/matplotlib/backends/backend_ps.py        
2009-03-18 15:45:07 UTC (rev 6989)
+++ branches/v0_98_5_maint/lib/matplotlib/backends/backend_ps.py        
2009-03-18 15:48:30 UTC (rev 6990)
@@ -11,7 +11,7 @@
 except ImportError:
     from md5 import md5 #Deprecated in 2.5
 
-from tempfile import gettempdir
+from tempfile import mkstemp
 from cStringIO import StringIO
 from matplotlib import verbose, __version__, rcParams
 from matplotlib._pylab_helpers import Gcf
@@ -911,15 +911,15 @@
         """
         isEPSF = format == 'eps'
         passed_in_file_object = False
+        fd, tmpfile = mkstemp()
         if is_string_like(outfile):
             title = outfile
-            tmpfile = os.path.join(gettempdir(), md5(outfile).hexdigest())
         elif is_writable_file_like(outfile):
             title = None
-            tmpfile = os.path.join(gettempdir(), 
md5(str(hash(outfile))).hexdigest())
             passed_in_file_object = True
         else:
             raise ValueError("outfile must be a path or a file-like object")
+        os.close(fd)
         fh = file(tmpfile, 'w')
 
         # find the appropriate papertype
@@ -1054,7 +1054,8 @@
         title = outfile
 
         # write to a temp file, we'll move it to outfile when done
-        tmpfile = os.path.join(gettempdir(), md5(outfile).hexdigest())
+        fd, tmpfile = mkstemp()
+        os.close(fd)
         fh = file(tmpfile, 'w')
 
         self.figure.dpi = 72 # ignore the dpi kwarg


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to