473,394 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Exiting os.spawnv's subroutine

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 closing
itself and returning to the main script. I have tried using sys.exit()
and exit() but these aren't doing anything.

What is the proper way to terminate this subroutine upon completion,
rather than waiting? Thank you.

Feb 17 '06 #1
3 1662
In article <11*********************@g14g2000cwa.googlegroups. com>,
"IamIan" <ia****@gmail.com> wrote:
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 closing
itself and returning to the main script. I have tried using sys.exit()
and exit() but these aren't doing anything.

What is the proper way to terminate this subroutine upon completion,
rather than waiting? Thank you.


Your description is a little ambiguous, but my guess is your
process just isn't done when you think it is. It's flushing
data to disk or something like that. Or it could be something
else. Why don't you write a sample program that works like
this, and demonstrates the problem, and then we'll know.

Donn Cave, do**@u.washington.edu
Feb 18 '06 #2
My code is below. As a single script there is no pause at the end of
the processing as there is with using os.spawnv... I am using the
P_WAIT value, and wonder if it is responsible for the extra time at the
end of each iteration. Could it take longer for the processing to be
"successful" when run under os.spawnv? Is there a way to manually send
a "success" exit code back to os.spawnv, rather than waiting for it?
Thanks.

Main script:
# Import subprocess modules
import os, sys, win32com.client

# Define arguments for subprocess
pyPath = "C:\\Python21\\python.exe"
contourScript = "C:\\Ian\\Python scripts\\subProcess2.py"
workspace = "D:\\GIS\\Test"

# Get a list of IMG files in the workspace for Contouring
filenames = os.listdir(workspace)
filenames = [filename.lower()
for filename in filenames
if (filename[-4:].lower() == ".img" and filename[0:2] != "h_" )]
for filename in filenames:

# Define filenames
print "Filename is " + filename
inImg = workspace + "\\" + filename
outContour50 = workspace + "\\contour50_" + filename[:-4] + ".shp"
outContour100 = workspace + "\\contour100_" + filename[:-4] +
".shp"
outContour200 = workspace + "\\contour200_" + filename[:-4] +
".shp"
outContour500 = workspace + "\\contour500_" + filename[:-4] +
".shp"

# Create parameter list
parameterList = []

# First parameter is the name of the Python executable
parameterList.append('python.exe')

# Second parameter is the full path of the Python script
parameterList.append(contourScript)

# The following parameters are the arguments for the Batch script
parameterList.append(inImg)
parameterList.append(outContour50)
parameterList.append(outContour100)
parameterList.append(outContour200)
parameterList.append(outContour500)

# Run subprocess
os.spawnv(os.P_WAIT, pyPath, parameterList)

print "All done!"
Secondary script:
# Import system modules
import sys, win32com.client

# Create the geoprocessor object
gp = win32com.client.Dispatch("esriGeoprocessing.GpDisp atch.1")

# Confirm license availability
print "ArcInfo license is " + str(gp.CheckProduct("ArcInfo"))
gp.SetProduct("ArcInfo")
gp.CheckOutExtension("Spatial")

# Set arguments to be passed to main script
inImg = sys.argv[1]
outContour50 = sys.argv[2]
outContour100 = sys.argv[3]
outContour200 = sys.argv[4]
outContour500 = sys.argv[5]

badImgList = []

try:
# For each IMG file, contour at 50, 100, and 200 meter intervals
gp.Contour_sa(inImg, outContour50, "50", "0", "1")
print "Successfully contoured at 50 meter interval!"

gp.Contour_sa(inImg, outContour100, "100", "0", "1")
print "Successfully contoured at 100 meter interval!"

gp.Contour_sa(inImg, outContour200, "200", "0", "1")
print "Successfully contoured at 200 meter interval!"

gp.Contour_sa(inImg, outContour500, "500", "0", "1")
print "Successfully contoured at 500 meter interval!"
except:
badImgList.append(filename)
print filename + " is no good! It's been added to the list!"

Feb 21 '06 #3
Strange but removing the try/except part of the second script (leaving
only the processing) removed the 2 minute lag at the end of each
subroutine.

Feb 22 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
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...
3
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...
1
by: nushin | last post by:
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...
4
by: SHPsalm139 | last post by:
If I'm in, say, a 3rd level sub and want to exit, not only the sub but the entire procedure, without a GoTo, can this be done without using switches?
7
by: OutdoorGuy | last post by:
Greetings, I'm still relatively new to C# and was wondering if there was a way to exit a subroutine (such as "Exit Sub" in VB)? I have the code below which performs validations. If the user...
0
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)...
0
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...
2
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...
8
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
marktang
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.