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

nushin nushin2 at yahoo.com
Thu Aug 7 18:39:34 EDT 2003


Thanks Jeff. Yes, i think it's the stdio buffering that causes
P_NOWAIT act asif it's a P_WAIT. I wish an additional parameter could
be added to spawnv( ) to toggle its stdout on/off.

Regards,
Nushin

Jeff Epler <jepler at unpythonic.net> wrote in message news:<mailman.1060257314.28503.python-list at python.org>...
> I don't see any problem with P_NOWAIT.  Take the following for example:
> 
> 	$ cat nushin.py
> 	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 nushin.py
> 	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 nushin.py | 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
> yet.
> 
> Here's what you see on a terminal without -u:
> 	$ python nushin.py
> 	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()
> 
> Jeff




More information about the Python-list mailing list