diff options
author | Steven Knight <knight@baldmt.com> | 2003-10-04 13:26:47 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2003-10-04 13:26:47 (GMT) |
commit | 176114b2c141bd950c2bc7231f829989fc7481b1 (patch) | |
tree | b1112e3617601cc0c98adc7e4eb2ae5576e0bca2 /src/engine | |
parent | 41a3eeec87272670f593f46ab8558d0ab99046f5 (diff) | |
download | SCons-176114b2c141bd950c2bc7231f829989fc7481b1.zip SCons-176114b2c141bd950c2bc7231f829989fc7481b1.tar.gz SCons-176114b2c141bd950c2bc7231f829989fc7481b1.tar.bz2 |
Execute commands using os.spawnvpe() if it's available. (J.T. Conklin)
Diffstat (limited to 'src/engine')
-rw-r--r-- | src/engine/SCons/Platform/posix.py | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/src/engine/SCons/Platform/posix.py b/src/engine/SCons/Platform/posix.py index 9b7e11c..e6b4b15 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'): |