summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathaniel J. Smith <njs@pobox.com>2016-05-13 18:52:21 -0700
committerNathaniel J. Smith <njs@pobox.com>2016-05-13 18:52:21 -0700
commit43e061b6bd67ff2d04c3891e2f4dd4d6dd683b26 (patch)
tree65fed68977f9db5d85eacc6a6093187dbf135995
parent2555e44986b6d1ffb34ea3aed511b5812d4e3923 (diff)
parent235f88674189547c50b72a11b7975bb231eddee5 (diff)
downloadnumpy-43e061b6bd67ff2d04c3891e2f4dd4d6dd683b26.tar.gz
Merge pull request #7614 from ales-erjavec/spawnv
BLD: Avoid using os.spawnve in favor of os.spawnv in exec_command
-rw-r--r--numpy/distutils/exec_command.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/numpy/distutils/exec_command.py b/numpy/distutils/exec_command.py
index 50f03feeb..4a4bc67f2 100644
--- a/numpy/distutils/exec_command.py
+++ b/numpy/distutils/exec_command.py
@@ -363,10 +363,14 @@ def _exec_command( command, use_shell=None, use_tee = None, **env ):
else:
argv = shlex.split(command)
+ # `spawn*p` family with path (vp, vpe, ...) are not available on windows.
+ # Also prefer spawn{v,vp} in favor of spawn{ve,vpe} if no env
+ # modification is actually requested as the *e* functions are not thread
+ # safe on windows (https://bugs.python.org/issue6476)
if hasattr(os, 'spawnvpe'):
- spawn_command = os.spawnvpe
+ spawn_command = os.spawnvpe if env else os.spawnvp
else:
- spawn_command = os.spawnve
+ spawn_command = os.spawnve if env else os.spawnv
argv[0] = find_executable(argv[0]) or argv[0]
if not os.path.isfile(argv[0]):
log.warn('Executable %s does not exist' % (argv[0]))
@@ -395,7 +399,7 @@ def _exec_command( command, use_shell=None, use_tee = None, **env ):
log.debug('Running %s(%s,%r,%r,os.environ)' \
% (spawn_command.__name__, os.P_WAIT, argv[0], argv))
- if sys.version_info[0] >= 3 and os.name == 'nt':
+ if env and sys.version_info[0] >= 3 and os.name == 'nt':
# Pre-encode os.environ, discarding un-encodable entries,
# to avoid it failing during encoding as part of spawn. Failure
# is possible if the environment contains entries that are not
@@ -431,7 +435,11 @@ def _exec_command( command, use_shell=None, use_tee = None, **env ):
else:
os.dup2(fout.fileno(), se_fileno)
try:
- status = spawn_command(os.P_WAIT, argv0, argv, encoded_environ)
+ # Use spawnv in favor of spawnve, unless necessary
+ if env:
+ status = spawn_command(os.P_WAIT, argv0, argv, encoded_environ)
+ else:
+ status = spawn_command(os.P_WAIT, argv0, argv)
except Exception:
errmess = str(get_exception())
status = 999