diff options
author | Ronan Lamy <ronan.lamy@gmail.com> | 2016-11-15 01:52:53 +0000 |
---|---|---|
committer | Ronan Lamy <ronan.lamy@gmail.com> | 2016-11-15 01:52:53 +0000 |
commit | 2645c616eb22dfe97df2e3062f3a70db47a09fdb (patch) | |
tree | dadfbe0a626d346216ab4e9e6fe1d44f70d35d4f /py/_path | |
parent | copy upstream pytest-2.9.2 and py-1.4.29 (diff) | |
parent | Move 2 scripts used only by PyPy to pypy/tool/ (diff) | |
download | pypy-2645c616eb22dfe97df2e3062f3a70db47a09fdb.tar.gz pypy-2645c616eb22dfe97df2e3062f3a70db47a09fdb.tar.bz2 pypy-2645c616eb22dfe97df2e3062f3a70db47a09fdb.zip |
hg merge default
Diffstat (limited to 'py/_path')
-rw-r--r-- | py/_path/local.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/py/_path/local.py b/py/_path/local.py index c1f7248add..a36f2b7645 100644 --- a/py/_path/local.py +++ b/py/_path/local.py @@ -780,7 +780,8 @@ class LocalPath(FSBase): mkdtemp = classmethod(mkdtemp) def make_numbered_dir(cls, prefix='session-', rootdir=None, keep=3, - lock_timeout = 172800): # two days + lock_timeout = 172800, # two days + min_timeout = 300): # five minutes """ return unique directory with a number greater than the current maximum one. The number is assumed to start directly after prefix. if keep is true directories with a number less than (maxnum-keep) @@ -848,6 +849,20 @@ class LocalPath(FSBase): for path in rootdir.listdir(): num = parse_num(path) if num is not None and num <= (maxnum - keep): + if min_timeout: + # NB: doing this is needed to prevent (or reduce + # a lot the chance of) the following situation: + # 'keep+1' processes call make_numbered_dir() at + # the same time, they create dirs, but then the + # last process notices the first dir doesn't have + # (yet) a .lock in it and kills it. + try: + t1 = path.lstat().mtime + t2 = lockfile.lstat().mtime + if abs(t2-t1) < min_timeout: + continue # skip directories too recent + except py.error.Error: + continue # failure to get a time, better skip lf = path.join('.lock') try: t1 = lf.lstat().mtime |