exec* exiting?

Alex Martelli aleaxit at yahoo.com
Sun Aug 19 17:28:37 EDT 2001


"Neil Macneale" <mac4-devnull at theory.org> wrote in message
news:3b80296d$0$322$8eec23a at newsreader.tycho.net...
> Why does the interpreter exit when I use the os.execl() function? Even
when
> the command works correctly, the interpreter exits. Am I supposed to run
> this function is a seperate thread?  Thats lame, if so.

The os.exec* functions *overwrite the current process* (which is running
the Python interpreter) with the executable you specify.  It's useless to
run them in a separate *thread*: the whole *process* is overwritten.

I'm sure Dr Ritchie and Dr Thompson, Turing Award winners for the
development of Unix (TM), which originated this arrangement, would
be extremely saddened by finding out that you've deemed their
brainchild 'lame' -- most particularly, don't let the ACM know, or they
might take away their Turing Awards, the computer science equivalent
of Nobel prizes, and wouldn't that be sad?

Nevertheless, if you're running on some Unix-derived system, you will
generally use os.fork to generate a new process first, then in the child
process (after setting the environment up) you will call os.exec* to
run the intended executable for the child-process.  On other operating
systems, if you don't intend for the interpreter process to terminate,
don't use os.exec*; there are other alternatives, although none of
them is as flexible and powerful as the one you consider 'lame'.  Look
at os.spawn* or os.system if the parent and child need no special
communication channels (pipes) between them, os.popen and its
relatives if you do want a pipe between the processes (having more
than one pipe is also possible, for bidirectional communication, but
that is prone to lock-ups unless both ends are very careful in their
I/O interactions).  Nowadays, sockets, rather than pipes, are often
considered to be more flexible and powerful for inter-process
communication (IPC).  Anyway, the alternatives are many, both for
starting another process and for communicating with it.


Alex






More information about the Python-list mailing list