From 04cf3cdfa0fead2235057ee788e6b90ce970c55f Mon Sep 17 00:00:00 2001 From: arigo Date: Sun, 4 Feb 2007 14:01:21 +0100 Subject: [PATCH] [svn r37901] 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. --HG-- branch : trunk --- py/path/local/local.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/py/path/local/local.py b/py/path/local/local.py index 90d990207..f461f4c1f 100644 --- a/py/path/local/local.py +++ b/py/path/local/local.py @@ -608,11 +608,19 @@ class LocalPath(common.FSPathBase, PlatformMixin): # 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: