473,830 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1684
In article <11************ *********@g14g2 000cwa.googlegr oups.com>,
"IamIan" <ia****@gmail.c om> 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.washingt on.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\\Pytho n scripts\\subPro cess2.py"
workspace = "D:\\GIS\\T est"

# Get a list of IMG files in the workspace for Contouring
filenames = os.listdir(work space)
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 + "\\contour5 0_" + filename[:-4] + ".shp"
outContour100 = workspace + "\\contour1 00_" + filename[:-4] +
".shp"
outContour200 = workspace + "\\contour2 00_" + filename[:-4] +
".shp"
outContour500 = workspace + "\\contour5 00_" + filename[:-4] +
".shp"

# Create parameter list
parameterList = []

# First parameter is the name of the Python executable
parameterList.a ppend('python.e xe')

# Second parameter is the full path of the Python script
parameterList.a ppend(contourSc ript)

# The following parameters are the arguments for the Batch script
parameterList.a ppend(inImg)
parameterList.a ppend(outContou r50)
parameterList.a ppend(outContou r100)
parameterList.a ppend(outContou r200)
parameterList.a ppend(outContou r500)

# 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("esri Geoprocessing.G pDispatch.1")

# Confirm license availability
print "ArcInfo license is " + str(gp.CheckPro duct("ArcInfo") )
gp.SetProduct(" ArcInfo")
gp.CheckOutExte nsion("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(i nImg, outContour50, "50", "0", "1")
print "Successful ly contoured at 50 meter interval!"

gp.Contour_sa(i nImg, outContour100, "100", "0", "1")
print "Successful ly contoured at 100 meter interval!"

gp.Contour_sa(i nImg, outContour200, "200", "0", "1")
print "Successful ly contoured at 200 meter interval!"

gp.Contour_sa(i nImg, outContour500, "500", "0", "1")
print "Successful ly contoured at 500 meter interval!"
except:
badImgList.appe nd(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
1678
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 >/dev/null &')) and when i check the process state code of hello.py by: ps -aux
3
10817
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 and Python 2.2.2 and i see that the program is either launched as Zombie state using spawnv(), or running in State "S" sleep in spawnl( ). Here's the sample code that launches my program: os.spawnv(os.P_NOWAIT,'/usr/bin/python',('python...
1
4777
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 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'))
4
1742
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
7632
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 fails to enter in a First name, then I want to set the focus to the control on the form and then exit the subroutine. Any ideas? private void btnSubmit_Click(object sender, System.EventArgs e) {
0
6473
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) gets each Ascii file in the workspace, converts it to a raster, sets the spatial reference, and hillshades it. The script works on its own. In the Main Script I can successfully pass parameters in a list, but no geoprocessing is ever initiated...
0
1008
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 exception with the tuple (0, 'Error'): >>> spawnv(P_WAIT, 'c:/mctools/bin/mc', ) Archelon Tool Driver 3.09 2005/02/16 No input file was given. Traceback (most recent call last):
2
1199
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 my python code, it doesn't work at all. Here is my code: exe = "c:\\curl.exe"
8
1976
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 with the references 3. The video gets converted to FLV - but the user shouldn't have to wait around for this to happen
0
9793
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10526
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10206
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5617
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5780
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4416
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3076
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.