On 8/23/20, Chris Angelico <ros...@gmail.com> wrote: > On Mon, Aug 24, 2020 at 7:40 AM dn via Python-list > >> As a 'general rule', isn't exec() something to be avoided? > > Nope, it's a very important tool. Not for every situation, of course, > but there are plenty of times when it's the right thing to do.
In POSIX, yes, but the faked implementation in Windows is almost always the wrong choice. Since the exec functions in Windows simply spawn a new process and exit the current process instead of replacing the executable image of the current process, they result in broken semantics for a waiting parent process, both in terms of getting the correct exit status and waiting for the process to exit. The result of the latter is an unworkable mess with console applications, since both the parent and child will compete for console I/O. For Windows, we need to spawn, wait, and proxy the exit status. If possible, the spawned child process should also be added to a kill-on-close job object, like the py.exe launcher does. That way if the waiting parent crashes or gets terminated, the spawned child will be terminated as well. -- https://mail.python.org/mailman/listinfo/python-list