From 4aac96fa138c1586314f32ddb1fb378e7db0ab1f Mon Sep 17 00:00:00 2001 From: hpk Date: Tue, 17 Mar 2009 15:12:10 +0100 Subject: [PATCH] [svn r63000] * do an as lightweight config.mktemp() as possible * avoid writing lock files if lock_timeout is 0 or None --HG-- branch : trunk --- py/path/local/local.py | 41 ++++++++++--------- py/path/local/testing/test_local.py | 2 - py/test/config.py | 2 +- .../testing/test_functional_dsession.py | 7 +--- 4 files changed, 23 insertions(+), 29 deletions(-) diff --git a/py/path/local/local.py b/py/path/local/local.py index 512d485d2..57f2e2cdb 100644 --- a/py/path/local/local.py +++ b/py/path/local/local.py @@ -618,25 +618,26 @@ 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(mypid)) - else: - 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: - pass - atexit.register(try_remove_lockfile) + if lock_timeout: + lockfile = udir.join('.lock') + mypid = os.getpid() + if hasattr(lockfile, 'mksymlinkto'): + lockfile.mksymlinkto(str(mypid)) + else: + 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: + pass + atexit.register(try_remove_lockfile) # prune old directories if keep: @@ -647,7 +648,7 @@ class LocalPath(common.FSPathBase, PlatformMixin): try: t1 = lf.lstat().mtime t2 = lockfile.lstat().mtime - if abs(t2-t1) < lock_timeout: + if not lock_timeout or abs(t2-t1) < lock_timeout: continue # skip directories still locked except py.error.Error: pass # assume that it means that there is no 'lf' diff --git a/py/path/local/testing/test_local.py b/py/path/local/testing/test_local.py index 6ed76cd60..99cc733e3 100644 --- a/py/path/local/testing/test_local.py +++ b/py/path/local/testing/test_local.py @@ -275,8 +275,6 @@ class TestExecution(LocalSetup): assert not numdir.new(ext=str(i-3)).check() def test_locked_make_numbered_dir(self): - if py.test.config.option.boxed: - py.test.skip("Fails when run as boxed tests") root = self.tmpdir for i in range(10): numdir = local.make_numbered_dir(prefix='base2.', rootdir=root, diff --git a/py/test/config.py b/py/test/config.py index 35965f3bd..3d415e8e0 100644 --- a/py/test/config.py +++ b/py/test/config.py @@ -140,7 +140,7 @@ class Config(object): return basetemp.mkdir(basename) else: return py.path.local.make_numbered_dir(prefix=basename + "-", - keep=0, rootdir=basetemp) + keep=0, rootdir=basetemp, lock_timeout=None) def getcolitems(self): return [self.getfsnode(arg) for arg in self.args] diff --git a/py/test/dsession/testing/test_functional_dsession.py b/py/test/dsession/testing/test_functional_dsession.py index 4c3abc8c1..a95d9085d 100644 --- a/py/test/dsession/testing/test_functional_dsession.py +++ b/py/test/dsession/testing/test_functional_dsession.py @@ -1,12 +1,6 @@ - -""" Tests various aspects of dist, like ssh hosts setup/teardown -""" - import py from py.__.test.dsession.dsession import DSession from test_masterslave import EventQueue -import os - class TestAsyncFunctional: def test_conftest_options(self, testdir): @@ -80,6 +74,7 @@ class TestAsyncFunctional: def test_nice_level(self, testdir): """ Tests if nice level behaviour is ok """ + import os if not hasattr(os, 'nice'): py.test.skip("no os.nice() available") testdir.makepyfile(conftest="""