executing an external program

Philip Swartzleonard starx at pacbell.net
Mon Apr 8 13:41:11 EDT 2002


Martin v. Löwis || Mon 08 Apr 2002 03:51:18a:

> mixo <mixo at beth.uniforum.org.za> writes:
> 
>> How can I continue execution of my script, and run only one instance
>> of the external program and keep track of what is doing so as to
>> avoid confusion?
> 
> On Unix, you can use os.fork/os.exec to create the subprocess
> asynchronously. You can then use os.wait to wait for the completion of
> the child process when you want to start the next process. For that,
> you have three modi operandi:
> 1. you invoke wait blockingly.
> 2. you invoke wait non-blockingly, and operate in a polling fashiong.
> 3. you install a SIGCLD handler, and start the next process when the
>    previous one terminates.

I don't really know anything about fork (or even if it works on other 
platforms), but you could also use threading. Create a thread that does 
nothing but call system() repetadly, and put the results on some kind of 
locked threadsafe variable/object (one of those queue.queue 
thigamajiggers?). Look at docs for the thread module if you think this 
path will help you.


-- 
Philip Sw "Starweaver" [rasx] :: www.rubydragon.com



More information about the Python-list mailing list