[py-svn] r37901 - py/trunk/py/path/local

arigo at codespeak.net arigo at codespeak.net
Sun Feb 4 14:01:23 CET 2007


Author: arigo
Date: Sun Feb  4 14:01:21 2007
New Revision: 37901

Modified:
   py/trunk/py/path/local/local.py
Log:
make_numbered_dir(): in a fork() situation, only the last process should remove
the .lock, otherwise the other processes run the risk of seeing their temporary
dir disappear.  For now we remove the .lock in the parent only (i.e. we assume
that the children finish before the parent).

This is needed for long-running pypy translate.py processes using
--fork-before.



Modified: py/trunk/py/path/local/local.py
==============================================================================
--- py/trunk/py/path/local/local.py	(original)
+++ py/trunk/py/path/local/local.py	Sun Feb  4 14:01:21 2007
@@ -608,11 +608,19 @@
         # put a .lock file in the new directory that will be removed at
         # process exit
         lockfile = udir.join('.lock')
+        mypid = os.getpid()
         if hasattr(lockfile, 'mksymlinkto'):
-            lockfile.mksymlinkto(str(os.getpid()))
+            lockfile.mksymlinkto(str(mypid))
         else:
-            lockfile.write(str(os.getpid()))
+            lockfile.write(str(mypid))
         def try_remove_lockfile():
+            # in a fork() situation, only the last process should
+            # remove the .lock, otherwise the other processes run the
+            # risk of seeing their temporary dir disappear.  For now
+            # we remove the .lock in the parent only (i.e. we assume
+            # that the children finish before the parent).
+            if os.getpid() != mypid:
+                return
             try:
                 lockfile.remove()
             except py.error.Error:



More information about the pytest-commit mailing list