classification
Title: os.execve puts process to background on windows
Type: Stage:
Components: Library (Lib) Versions: Python 3.4
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: BreamoreBoy, amaury.forgeotdarc, anacrolix, eric.smith, loewis, piotr.dobrogost, r.david.murray, steve.dower, techtonik, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2010-07-03 11:29 by techtonik, last changed 2014-06-19 21:51 by BreamoreBoy.

Messages (7)
msg109176 - (view) Author: anatoly techtonik (techtonik) Date: 2010-07-03 11:29
os.execve() is said to replace current process with new program. Unfortunately, when you try to call script that contains os.execve() on windows - that script spawns background process and control is immediately returned to the calling program. Does it behave the same on Unix?

Is there any way to replace current process on Windows so that references to calling parent process are not lost and it could wait for execution to complete?
msg109179 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-07-03 12:16
on Windows, exec() does not really replace the current process. It creates a new process (with a new pid), and exits the current one.

Hence the calling program only sees that the script has terminated.

I don't see any easy solution on Windows, except than using subprocess.Popen(), and exit the script when the subprocess terminates.
msg109182 - (view) Author: anatoly techtonik (techtonik) Date: 2010-07-03 13:07
Does that mean that windows doesn't allow process replacement at all?

I remember the time then game NoCD loaders were somehow able to load, patch and execute main program in their address space.
msg110463 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2010-07-16 17:10
I believe it's true that Windows does not offer process replacement. I'm sure you could perform some tricks by essentially writing your own loader, but the practical answer is no. It might be worth looking into how cygwin implements exec().
msg169174 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-08-27 00:11
This looks like the answer to the cygwin question, assuming things haven't changed:

http://cygwin.com/ml/cygwin-developers/2001-02/msg00106.html

Basically, it does the same thing as Python, except that a special return code is reported by the execing process to signal to whoever created the execing process that an exec has occurred.

Would it be at all useful to add such a return code?
msg194379 - (view) Author: Piotr Dobrogost (piotr.dobrogost) Date: 2013-08-04 14:22
This is unexpected and makes people wonder what's going on. See http://stackoverflow.com/q/7004687/95735 and http://stackoverflow.com/q/7264571/95735.
msg221031 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-06-19 21:51
I've changed the nosy list according to the experts index for the os module and Windows, sorry if I've named anyone I shouldn't have.
History
Date User Action Args
2014-06-19 21:51:50BreamoreBoysetnosy: + tim.golden, BreamoreBoy, loewis, zach.ware, steve.dower
messages: + msg221031
2013-08-04 14:22:31piotr.dobrogostsetmessages: + msg194379
2013-08-04 13:58:51anacrolixsetnosy: + anacrolix
2013-08-04 13:49:49piotr.dobrogostsetnosy: + piotr.dobrogost
2012-08-27 00:11:15r.david.murraysetnosy: + r.david.murray

messages: + msg169174
versions: + Python 3.4, - Python 2.6, Python 2.7, Python 3.2
2010-07-16 17:10:01eric.smithsetnosy: + eric.smith
messages: + msg110463
2010-07-03 13:07:37techtoniksetmessages: + msg109182
2010-07-03 12:16:34amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg109179
2010-07-03 11:29:33techtonikcreate