Use os.exec rather than sys.exit(subprocess.call(...))
adamchainz opened this issue · 7 comments
Using an os.exec* function, when available (Unix, Windows) will replace the Python wrapper process, rather than keeping it around until zig has finished. This saves memory and makes processes easier to debug.
You should be able to change:
sys.exit(subprocess.call([
os.path.join(os.path.dirname(__file__), "{entry_name}"),
*sys.argv[1:]
]))to something like:
path = os.path.join(os.path.dirname(__file__), "{entry_name}")
os.execvp("zig", path, *sys.argv[1:])They are available on Windows but do not perform usefully.
Oh interesting, good to know. Perhaps there could be a check to use exec on unix only?
There could be, but I'm worried about issues that arise from using different mechanisms on Unix and Windows. (This is why it doesn't already use os.exec.)
For what it's worth, the zig binary itself will use execve on Unix for zig run and CreateProcessW on Windows.
Does it wait for the process to terminate?
The CreateProcessW path? Yes, I believe this would be equivalent to the status quo python code.
To be clear I'm not saying you can get execve semantics on Windows, just that zig does use execve when it can and where it makes sense to.
No objection to using os.execvp on Unix then.