diff options
| author | Ales Erjavec <ales.erjavec@fri.uni-lj.si> | 2016-05-10 14:17:53 +0200 |
|---|---|---|
| committer | Ales Erjavec <ales.erjavec@fri.uni-lj.si> | 2016-05-10 15:52:29 +0200 |
| commit | 235f88674189547c50b72a11b7975bb231eddee5 (patch) | |
| tree | e10d6e1a76452fa5a9a6521b82ce1d5b5e07e28c /numpy/distutils/exec_command.py | |
| parent | 49d1298cbaf41077f22b08cc2d9bf0e482d1e374 (diff) | |
| download | numpy-235f88674189547c50b72a11b7975bb231eddee5.tar.gz | |
BLD: Avoid using os.spawnve in favor of os.spawnv in exec_command
The env modifying spawn* function are not thread safe on windows (python
issue6476) so avoid using them unless so requested by the caller.
References #7607
Diffstat (limited to 'numpy/distutils/exec_command.py')
| -rw-r--r-- | numpy/distutils/exec_command.py | 16 |
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 |
