On Tue, Jun 21, 2011 at 12:26 PM, Ian wrote:
myForkedScript has code like this:
Is using os._exit() the correct way to get a return value back to the
"The" correct way, no, but it is "a" correct way (and cheaper than
using a pipe to pickle and unpickle failure, the way the subprocess
module does it, for instance). In any case, you *should* call
os._exit() either directly or indirectly after a successful fork
but a failed exec.
On Jun 21, 1:54?pm, Ian Kelly wrote:
sys.exit() is the preferred way.
Using sys.exit() after a fork() has other risks (principally,
duplication of pending output when flushing write-mode streams),
which is why os._exit() is provided.
I thought the value 'n', passed in os._exit(n) would be the value I
get returned. ?In the case of a failure, I get 256 returned rather
According to the docs ...
[snip documentation and description]
However, I would advise using the subprocess module for this instead
of the os module (which is just low-level wrappers around system
Indeed, subprocess gives you convenience, safety, and platform
independence (at least across POSIX-and-Windows) with a relatively
low cost. As long as the cost is low enough (and it probably is)
I agree with this.
In article <d195a74d-e173-4168-8812-c03fc02e8da7 at fr19g2000vbb.googlegroups.com>
Where did you find the Unix docs you pasted in? I didn't find it in
the man pages. Thank you. Based on what you say, I will change my
os._exit() to sys.exit().
Not sure where Ian Kelly's documentation came from, but note that on
Unix, the "os" module also provides os.WIFSIGNALED, os.WTERMSIG,
os.WIFEXITED, and os.WEXITSTATUS for dissecting the "status"
integer returned from the various os.wait* calls.
Again, if you use the subprocess module, you are insulated from
this sort of detail (which, as always, has both advantages and