If you do not null out the output of your parent process that launches
a child process by os.spawnv( ) in P_NOWAIT mode, you will see that
your child process is launched *synchronously* instead of
asynchronously. This is a bug!
Here's a code sample:
In your parent.py file, call child.py as
os.spawnv(os.P_NOWAIT,'/usr/bin/python',('python', 'child.py'))
then, make sure your child.py prints a *hello child* to screen about
2000000 times, and your parent.py prints a *hello parent* message,
then execute your file in a shell as:
python parent.py
then, you would see that whenever your child.py is finished, then
parent.py finishes, i.e., a synchronous call.
Now, null out the output of your parent process as:
python parent.py > /dev/null
then, your parent.py finishes first while child.py is still running,
i.e., an asynchronous call. Please correct me if i am wrong.
Regards,
Nushin 1 4761 nu*****@yahoo.com (nushin) wrote in message If you do not null out the output of your parent process that launches a child process by os.spawnv( ) in P_NOWAIT mode, you will see that your child process is launched *synchronously* instead of asynchronously. This is a bug!
Here's a code sample:
In your parent.py file, call child.py as
os.spawnv(os.P_NOWAIT,'/usr/bin/python',('python', 'child.py'))
then, make sure your child.py prints a *hello child* to screen about 2000000 times, and your parent.py prints a *hello parent* message, then execute your file in a shell as:
python parent.py
then, you would see that whenever your child.py is finished, then parent.py finishes, i.e., a synchronous call.
Now, null out the output of your parent process as:
python parent.py > /dev/null
then, your parent.py finishes first while child.py is still running, i.e., an asynchronous call. Please correct me if i am wrong.
Regards, Nushin
Jeff Epler has shed some light on this issue. Thanks to him.
================================================== =========
Jeff Epler <je****@unpythonic.net> wrote in message news:<ma**********************************@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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: nushin |
last post by:
Greetings,
I am running RedHat 7.3 and trying to spawn a hello.py program from
hello_driver.py by using spawn*( ) API, as a P_NOWAIT :
os.spawnv(os.P_NOWAIT,'/usr/bin/python',('python hello.py...
|
by: nushin |
last post by:
Try to launch a test program that prints hello world for a minute or
so using, spawnv( ) or spawnl( ). Check to see the process state code
that the program is running. I am using RedHat Linux 7.3...
|
by: Jorge Godoy |
last post by:
Hi!
I must have been searching in the wrong places or with the wrong
keywords but I couldn't find out how to implement something such as
what is done by the threading module on Windows (95, 98...
|
by: muttu2244 |
last post by:
hi all
i tried running a exe file info.exe from the spawnle cmd, its running
fine from the interactive mode, but when i try to run the same info.exe
file from a python file, its giving me the...
|
by: IamIan |
last post by:
I've had to migrate back to Python 2.1 and am now trying to use
os.spawnv to get around a memory leak (either in Python or ArcGIS or
both) in a geoprocessing script.
This script (Second Script)...
|
by: IamIan |
last post by:
I am using os.spawnv in Python 2.1 to do some geoprocessing in a
subroutine/process. Everything works great, except when the processing
is done the subroutine just waits for a couple minutes before...
|
by: Chris Reuter |
last post by:
I've been trying to start a particular external program from Python
using os.spawnv(). This works perfectly under Linux but under
Windows, it first runs the program, then throws an OSError...
|
by: Fabio Chelly |
last post by:
Hi,
I have a command line that works fine when I execute it directly:
c:\\curl.exe -T c:\\upload.txt -u login:pwd ftp://ftp-myurl --ftp-ssl
But when I try to use os.spawnv to excute it from...
|
by: Henrik Lied |
last post by:
Hi there!
I'm trying to convert a video in a background process.
The scenario I'm after:
1. The user uploads a video
2. The video is saved in my media directory, and the database is
populated...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |