process wrapper?

Donn Cave donn at u.washington.edu
Mon Mar 29 22:04:58 CEST 2004


In article <QZ2dnbPGnqPo6_Xd38DK-g at speakeasy.net>,
 "Steve @ Waypath" <steve at waypath.com> wrote:

> Thanks for the reply. I haven't yet implemented a working spawnv call, so
> I'm not confident my tests are valid. Here's a sample:
> 
> ##########
> File: test1.py
> ------------
> import os, time
> if __name__=='__main__':
>  os.spawnv(os.P_NOWAIT,'python',['test2.py'])

OK, that can be fixed.

When the documentation says "path" for some functions, and
"file" for others (e.g., spawnvp), the distinction is that
"path" includes the directory specification, either absolute
or relative to the current working directory.  spawnv wants
a path, so the above doesn't work unless "python" is a file
in your current working directory.  To resolve this problem,
I would just write in the absolute path, or you may use spawnvp
instead.

But don't give it python's path.  Instead, at least consider
invoking the Python program file directly - put its path there
as the 2nd parameter, not python's.  Then your argument list
(the 3rd parameter) will be correct as written.  If you invoke
python itself, then you'll need to make test2.py the second
argument, directing python to interpret that file.  If you
decide to do as I suggest, test2.py will have to be executable
(chmod 755) and start with a line like "#!/usr/bin/python", as
appropriate for your system.  From there on, your test1.py
program no longer needs to know how test2.py is actually
implemented.


> ###########
> While test 1 is running, a ps (in another shell):
> # ps x | grep python
> 11726 pts/1  S   0:00  python test1.py
> 11727 pts/1  Z   0:00 [python <defunct>]
> 11729 pts/2  S   0:00 grep python
> 
> ###########
> I see this defunct thing with every spawnv test I try. The defunct process
> goes away when the calling process (test1.py, in this case) finishes. Where
> am I going wrong here?

It's a zombie!  UNIX leaves a dead process in the table as
long as its parent might come back and ask for the status.
It goes either when the parent gets its status with a wait
function (like waitpid()), or when the parent exits.

   Donn Cave, donn at drizzle.com



More information about the Python-list mailing list