spawnv( ) or spawnl( ) do not launch a normal running process in Python 2.2.2?
Jeff Epler
jepler at unpythonic.net
Thu Aug 7 07:54:35 EDT 2003
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