From: stevenknight Date: Sat, 4 Oct 2003 13:26:47 +0000 (+0000) Subject: Execute commands using os.spawnvpe() if it's available. (J.T. Conklin) X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=81b41ea7350e8f88656ff625e73c3fa9644b1208;p=scons.git Execute commands using os.spawnvpe() if it's available. (J.T. Conklin) git-svn-id: http://scons.tigris.org/svn/scons/trunk@809 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 692f3e3f..61011915 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -10,6 +10,11 @@ RELEASE X.XX - XXX + From J.T. Conklin: + + - On POSIX, execute commands with the more modern os.spawnvpe() + function, if it's available. + From Charles Crain: - Add support for a JARCHDIR variable to control changing to a diff --git a/src/engine/SCons/Platform/posix.py b/src/engine/SCons/Platform/posix.py index 9b7e11c4..e6b4b159 100644 --- a/src/engine/SCons/Platform/posix.py +++ b/src/engine/SCons/Platform/posix.py @@ -75,6 +75,13 @@ def env_spawn(sh, escape, cmd, args, env): return stat | 0x80 return stat >> 8 +def spawn_spawn(sh, escape, cmd, args, env): + args = [sh, '-c', string.join(args)] + stat = os.spawnvpe(os.P_WAIT, sh, args, env) + # os.spawnvpe() returns the actual exit code, not the encoding + # returned by os.waitpid() or os.system(). + return stat + def fork_spawn(sh, escape, cmd, args, env): pid = os.fork() if not pid: @@ -178,16 +185,29 @@ def piped_fork_spawn(sh, escape, cmd, args, env, stdout, stderr): def generate(env): + # If os.spawnvpe() exists, we use it to spawn commands. Otherwise + # if the env utility exists, we use os.system() to spawn commands, + # finally we fall back on os.fork()/os.exec(). + # + # os.spawnvpe() is prefered because it is the most efficient. But + # for Python versions without it, os.system() is prefered because it + # is claimed that it works better with threads (i.e. -j) and is more + # efficient than forking Python. + # + # NB: Other people on the scons-users mailing list have claimed that + # os.fork()/os.exec() works better than os.system(). There may just + # not be a default that works best for all users. + + if os.__dict__.has_key('spawnvpe'): + spawn = spawn_spawn + elif env.Detect('env'): + spawn = env_spawn + else: + spawn = fork_spawn - # If the env command exists, then we can use os.system() - # to spawn commands, otherwise we fall back on os.fork()/os.exec(). - # os.system() is prefered because it seems to work better with - # threads (i.e. -j) and is more efficient than forking Python. if env.Detect('env'): - spawn = env_spawn pspawn = piped_env_spawn else: - spawn = fork_spawn pspawn = piped_fork_spawn if not env.has_key('ENV'):