[issue19124] os.execv executes in background on Windows

Eryk Sun report at bugs.python.org
Sun Mar 21 09:04:18 EDT 2021


Eryk Sun <eryksun at gmail.com> added the comment:

> On Windows, the new process is executed in the background but 
> can send output to a console if the original process was 
> started in a console.

C execv[e]() is a mess for console applications. The child process is competing for console input with an ancestor process in the console session, which is typically a CLI shell such as CMD or PowerShell. This is dysfunctional. It's worth either fixing or deprecating. It's not worth documenting since it's way off spec compared to exec() in POSIX systems. exec() is supposed to overlay the current process with a new image, not terminate the current process. That cannot be implemented in Windows, but we could do our best to emulate it. 

The implementation could leave the current Python process running in much the same way as a launcher functions, i.e. wait for the child process to exit and proxy its exit status, and set the child process in a kill-on-close job object.

It would be better at this point to use subprocess.Popen() to implement os.exec*, considering it can work concurrently with itself, without race conditions involving inheritable handles. nt.spawnv[e](), nt.waitpid(), and nt.system() could also be implemented with subprocess.

----------
assignee: docs at python -> 
components: +Extension Modules, Library (Lib) -Documentation
versions: +Python 3.10 -Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue19124>
_______________________________________


More information about the Python-bugs-list mailing list