[svn r63000] * do an as lightweight config.mktemp() as possible

* avoid writing lock files if lock_timeout is 0 or None

--HG--
branch : trunk
This commit is contained in:
hpk 2009-03-17 15:12:10 +01:00
parent 47a91d2aa9
commit 4aac96fa13
4 changed files with 23 additions and 29 deletions

View File

@ -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'

View File

@ -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,

View File

@ -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]

View File

@ -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="""