Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #8115

Re: How to get return values of a forked process

From Ian <ian.lake@rocketmail.com>
Newsgroups comp.lang.python
Subject Re: How to get return values of a forked process
Date 2011-06-21 12:17 -0700
Organization http://groups.google.com
Message-ID <d195a74d-e173-4168-8812-c03fc02e8da7@fr19g2000vbb.googlegroups.com> (permalink)
References <ae67ad89-86f4-4374-9127-18f0193d23cc@m10g2000yqd.googlegroups.com> <mailman.239.1308682529.1164.python-list@python.org>

Show all headers | View raw


On Jun 21, 1:54 pm, Ian Kelly <ian.g.ke...@gmail.com> wrote:
> On Tue, Jun 21, 2011 at 12:26 PM, Ian <ian.l...@rocketmail.com> wrote:
> > myForkedScript has code like this:
> > if fail:
> >    os._exit(1)
> > else:
> >    os._exit(os.EX_OK)
>
> > Is using os._exit() the correct way to get a return value back to the
> > main process?
>
> sys.exit() is the preferred way.
>
> > 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
> > than 1.
>
> According to the docs, on Unix:
>
> """
> Wait for completion of a child process, and return a tuple containing
> its pid and exit status indication: a 16-bit number, whose low byte is
> the signal number that killed the process, and whose high byte is the
> exit status (if the signal number is zero); the high bit of the low
> byte is set if a core file was produced.
> """
>
> And on Windows:
>
> """
> Wait for completion of a process given by process handle pid, and
> return a tuple containing pid, and its exit status shifted left by 8
> bits (shifting makes cross-platform use of the function easier).
> """
>
> (256 >> 8) == 1
>
> However, I would advise using the subprocess module for this instead
> of the os module (which is just low-level wrappers around system
> calls).

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().

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to get return values of a forked process Ian <ian.lake@rocketmail.com> - 2011-06-21 11:26 -0700
  Re: How to get return values of a forked process Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-21 12:54 -0600
    Re: How to get return values of a forked process Ian <ian.lake@rocketmail.com> - 2011-06-21 12:17 -0700
      Re: How to get return values of a forked process Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-21 13:31 -0600
      Re: How to get return values of a forked process Chris Torek <nospam@torek.net> - 2011-06-21 20:11 +0000

csiph-web