spawnv( ) or spawnl( ) do not launch a normal running process in Python 2.2.2?

Jeff Epler jepler at
Thu Aug 7 13:54:35 CEST 2003

I don't see any problem with P_NOWAIT.  Take the following for example:

	$ cat
	import os

	p = os.spawnvp(os.P_NOWAIT, 'sh',
                       ['sh', '-c', 'sleep 1; echo from spawnv'])
	print "from program"
	print "waitpid returns:", os.waitpid(p, 0)
	$ python -u
	from program
	waitpid returns:from spawnv
         (2826, 0)

Now, if the program completed very quickly, it's a coin-flip whether its
output would appear before "from program".  In this case, I made sure
the program would take a really long time (1 second) to complete.

When running without -u but not on a terminal, you might see
	$ python | cat
	from spawnv
	from program
	waitpid returns: (2832, 0)
.. this is because the Python process has printed "from program", but
stdio buffering has kept it from actually being written to the output

Here's what you see on a terminal without -u:
	$ python
	from program
	from spawnv
	waitpid returns: (2835, 0)
This is the same thing you'd see if the program said
	print "from program"; sys.stdout.flush()


More information about the Python-list mailing list