multi-threaded *nix program needs to spawn an external program/script 
Author Message
 multi-threaded *nix program needs to spawn an external program/script

Would it make sense to add a function to python for *nix systems
    that would do the "start an executable file as a new process"?

If you have a multi-threaded program and some of the threads sometimes
need to spawn off new external programs or script.

You can do the following under win32, which starts the command
in a new process without forking():

    win32api.WinExec(command, ...)

It works great.

However, *nix systems don't have the "Start an executable file as a
new process" system call (just fork/exec).

I've tried various alternatives, which aren't working, such as:
    * os.system() works for a while, but:
          Eventually, at least on solaris, extra copies of the
          parent process are left{*filter*} around and never go
          away (they are not zombies - the zombies are being
          reaped).

    * python code doing the os.fork() + os.exec().

      This is the least reliable of all:  It leaves around lots
      of extra forked() but not defunct/zombie processes.

      With threads, if you're going to fork + exec, you're not supposed to
      do anything between the fork + exec or you're asking for trouble.

      Trying the os.fork() + os.exec() in an interpreted program is
      probably asking for trouble (and sure enough, trouble happens).

From what I've noticed, read, and heard, fork() inside threads() is
basically a bad idea.  Different OSes have different ideas,
bugs, etc.

But people are bound to need to have threaded programs spawn off separate
processes to do something in *nix.  (We are in that situation.)

What is the solution?  Would it make sense to add a function to python
for *nix systems that would do the "start an executable file as a
new process" that would work on at least *nix systems?

Or is there another solution?

Thanks!



Mon, 26 Jul 2004 06:17:29 GMT  
 multi-threaded *nix program needs to spawn an external program/script

Quote:

> Would it make sense to add a function to python for *nix systems
>     that would do the "start an executable file as a new process"?

Try os.spawnv(); it should work for both Unix and Windows.
  http://www.python.org/doc/current/lib/os-process.html

## Jason Orendorff    http://www.jorendorff.com/



Mon, 26 Jul 2004 06:34:13 GMT  
 multi-threaded *nix program needs to spawn an external program/script

| > Would it make sense to add a function to python for *nix systems
| >     that would do the "start an executable file as a new process"?
|
| Try os.spawnv(); it should work for both Unix and Windows.
|   http://www.python.org/doc/current/lib/os-process.html

Yes, though according to him, that shouldn't work - he says, on Solaris,
in a threaded program, you mustn't "do anything" between fork and exec,
and fork and exec called separately from Python don't work for him for
that reason.  os.spawnv is implemented in Python.

I think it would be worth a try.  I think os.spawnv will work as well
as os.system.

The next step would be to recode os.spawnve in a C module.  I don't know
anything about this Solaris problem, but if he's right, that would help.
(But then what's wrong with os.system?)

Of course if there's a system or thread library function that addresses
this need, that would obviously be the way to go.




Mon, 26 Jul 2004 08:49:19 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Problems with a multi-threaded program

2. Debugging Multi-Threaded Python Programs

3. Any detailed tutor for python multi-thread programming?

4. Any detailed tutor for python multi-thread programming?

5. python and multi-threaded C programs

6. Using TCL in a multi-threaded program

7. Invoking a external program from a script

8. sharing external functions between cms rexx programs and xedit rexx programs

9. Need help: running an external program from a CL.

10. Help: Fortran program as a thread of a C program

11. Scriptometer: measuring the ease of SOP (Script Oriented Programming) of programming languages

12. Scriptometer: measuring the ease of SOP (Script Oriented Programming) of programming languages

 

 
Powered by phpBB® Forum Software