Multiple Processes on Unix with Python

Donn Cave donn at oz.net
Fri Mar 23 01:46:38 EST 2001


Quoth Nickson Fong <nickson at centropolisfx.com>:
| this is helpful - what i really want to do is>
| for example: i have a 2 processor irix machine and i want to launch 2
| processes. 
|
| proc #1 = render frames 1-10
| proc #2 = render frames 11-20
|
|
| os.fork os.execv os.wait are things that i have been reading.....
|
| question: why do you os.spawnv?

Just to be different.  Seriously, I have always thought that a
fork+exec function would be a worthwhile convenience, and here
it is.  You can see for yourself in os.py, it's no more than
a fork and exec, plus waitpid depending on the option, but
notice that it has better than average exception handling.
And it's actually a Windows function, so it's a little more
cross platform portable than fork & exec.

Really I think the big payoff is to use it instead of system(),
with generated arguments.  Like,
   os.spawnv(os.P_WAIT, '/usr/bin/lpr', ('lpr', '-P', printer, file))
instead of
   os.system('lpr -P %s %s' % (printer, file))

If the input is bad (printer or file), the first is much less
scary than the second.

	Donn Cave, donn at oz.net



More information about the Python-list mailing list