From 411157756b7ad80203ffe458ee145964862d9c94 Mon Sep 17 00:00:00 2001 From: hpk Date: Thu, 8 Feb 2007 18:39:03 +0100 Subject: [PATCH] [svn r38184] avoid globals and add a comment --HG-- branch : trunk --- py/test/config.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/py/test/config.py b/py/test/config.py index db4af0e1e..bfdd21d52 100644 --- a/py/test/config.py +++ b/py/test/config.py @@ -6,18 +6,17 @@ from py.__.test.defaultconftest import adddefaultoptions optparse = py.compat.optparse -# XXX move to Config class -basetemp = None -_pid = None -def ensuretemp(string, dir=1): +def ensuretemp(string, dir=1, _pid2dir={}): """ return temporary directory path with the given string as the trailing part. """ - global basetemp, _pid - currpid = py.std.os.getpid() - if basetemp is None or _pid != currpid: - _pid = currpid + # we may be in a forking situation and want to use + # separate dirs then (XXX or not?) + pid = py.std.os.getpid() + basetemp = _pid2dir.get(pid, None) + if basetemp is None: basetemp = py.path.local.make_numbered_dir(prefix='pytest-') + _pid2dir[pid] = basetemp return basetemp.ensure(string, dir=dir) class CmdOptions(object):