@@ -655,6 +655,7 @@ def _use_posix_spawn():
655655
656656
657657_USE_POSIX_SPAWN = _use_posix_spawn ()
658+ _HAVE_POSIX_SPAWNP = hasattr (os , 'posix_spawnp' )
658659
659660
660661class Popen (object ):
@@ -1442,7 +1443,10 @@ def _get_handles(self, stdin, stdout, stderr):
14421443
14431444
14441445 def _posix_spawn (self , args , executable , env , restore_signals ):
1445- """Execute program using os.posix_spawn()."""
1446+ """Execute program using os.posix_spawnp().
1447+
1448+ Or use os.posix_spawn() if os.posix_spawnp() is not available.
1449+ """
14461450 if env is None :
14471451 env = os .environ
14481452
@@ -1456,7 +1460,10 @@ def _posix_spawn(self, args, executable, env, restore_signals):
14561460 sigset .append (signum )
14571461 kwargs ['setsigdef' ] = sigset
14581462
1459- self .pid = os .posix_spawn (executable , args , env , ** kwargs )
1463+ if _HAVE_POSIX_SPAWNP :
1464+ self .pid = os .posix_spawnp (executable , args , env , ** kwargs )
1465+ else :
1466+ self .pid = os .posix_spawn (executable , args , env , ** kwargs )
14601467
14611468 def _execute_child (self , args , executable , preexec_fn , close_fds ,
14621469 pass_fds , cwd , env ,
@@ -1484,7 +1491,7 @@ def _execute_child(self, args, executable, preexec_fn, close_fds,
14841491 executable = args [0 ]
14851492
14861493 if (_USE_POSIX_SPAWN
1487- and os .path .dirname (executable )
1494+ and ( _HAVE_POSIX_SPAWNP or os .path .dirname (executable ) )
14881495 and preexec_fn is None
14891496 and not close_fds
14901497 and not pass_fds
0 commit comments