Re: Unusual Python interpreter problem with os.fork()

Discussion in 'Python' started by Jean-Paul Calderone, Mar 6, 2009.

  1. On Fri, 6 Mar 2009 05:00:03 -0800 (PST), DLitgo <> wrote:
    >Hello everyone,
    >
    >I have a curious problem which I'm wondering if anyone here can shed
    >some light on. I'm basically just following along with a guide which
    >is going through some of the os module, and I'm running some examples
    >in the python interpreter on mac os x (accessed through terminal/
    >bash).
    >
    >Basically all I did was use os.fork() which caused this strange
    >problem:
    >
    >Macintosh:~ $ python
    >Python 2.5.1 (r251:54863, Jan 13 2009, 10:26:13)
    >[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
    >Type "help", "copyright", "credits" or "license" for more information.
    >>>>
    >>>> import os
    >>>> pid = os.fork()


    As soon as this returns, you have two CPython processes reading from stdin
    and writing to stdout. They fight over your input and their output gets
    interleaved in non-deterministic ways. Basically, you probably don't ever
    want to do this.

    Jean-Paul
    Jean-Paul Calderone, Mar 6, 2009
    #1
    1. Advertising

  2. Jean-Paul Calderone

    DLitgo Guest

    On Mar 6, 7:20 am, Jean-Paul Calderone <> wrote:
    > On Fri, 6 Mar 2009 05:00:03 -0800 (PST), DLitgo <> wrote:
    > >Hello everyone,

    >
    > >I have a curious problem which I'm wondering if anyone here can shed
    > >some light on. I'm basically just following along with a guide which
    > >is going through some of the os module, and I'm running some examples
    > >in the python interpreter on mac os x (accessed through terminal/
    > >bash).

    >
    > >Basically all I did was use os.fork() which caused this strange
    > >problem:

    >
    > >Macintosh:~ $ python
    > >Python 2.5.1 (r251:54863, Jan 13 2009, 10:26:13)
    > >[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
    > >Type "help", "copyright", "credits" or "license" for more information.

    >
    > >>>> import os
    > >>>> pid = os.fork()

    >
    > As soon as this returns, you have two CPython processes reading from stdin
    > and writing to stdout.  They fight over your input and their output gets
    > interleaved in non-deterministic ways.  Basically, you probably don't ever
    > want to do this.
    >
    > Jean-Paul


    Okay cool, I guess the example wasn't meant to be run in the
    interpreter then :) Thanks for the reply.
    DLitgo, Mar 6, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. William A. Sempf

    Unusual performance problem.

    William A. Sempf, Aug 27, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    375
    William A. Sempf
    Aug 27, 2003
  2. Scott David Daniels

    Unusual Python Sighting

    Scott David Daniels, Sep 10, 2005, in forum: Python
    Replies:
    1
    Views:
    278
  3. Replies:
    3
    Views:
    760
    Ziga Seilnacht
    Jan 3, 2007
  4. Eric Snow

    os.fork and pty.fork

    Eric Snow, Jan 8, 2009, in forum: Python
    Replies:
    0
    Views:
    571
    Eric Snow
    Jan 8, 2009
  5. DLitgo
    Replies:
    0
    Views:
    342
    DLitgo
    Mar 6, 2009
Loading...

Share This Page