473,396 Members | 2,158 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,396 software developers and data experts.

Get python to continue if process hangs

1
Hi All,

I am using python to script some processes using ESRI's ArcMap geoprocessor module.

One of the utilities I have compacts my spatial database. When I run my script, sometimes it hangs on the compact call, and then the rest of the script doesn't complete. Other times it completes just fine but can't be trusted to finish.

I don't think there is a way for python to check the status of the process to see if it has hung. So, was wondering if there is a way to tell python to move on to the next line in the script if it doesn't finish within say an hour.

OR, is there a way to call the compact routines from a different python script, and have it return after a set amount of time?

Anyway, pretty new to this python, but am learning. If anyone has any better suggestions, I'm open to them.

Thanks in advance,

R_

here is an example snippet
Expand|Select|Wrap|Line Numbers
  1. import sys, string, os, arcgisscripting, shutil
  2.  
  3. # Create the Geoprocessor object
  4. gp = arcgisscripting.create()
  5.  
  6. WCH_gdb = "\\\\hgis01\\gishome\\ladietz\\WCH.gdb"
  7.  
  8. gp.Compact_management(WCH_gdb)
  9.  
  10.  
  11.  
Dec 17 '10 #1
2 4030
dwblas
626 Expert 512MB
I would use multiprocessing. You have 2 processes, the geoprocessor module and the timer, so you have to use a method that can handle multiple processes. The following is an example of a time out.
Expand|Select|Wrap|Line Numbers
  1. import time
  2. from multiprocessing import Process
  3.  
  4. class TestClass():
  5.  
  6.    def test_f(self, name):
  7.       ctr = 0
  8.       while True:
  9.          ctr += 1
  10.          print ctr, name
  11.          time.sleep(0.5)
  12.  
  13. if __name__ == '__main__':
  14.    CT=TestClass()
  15.    p = Process(target=CT.test_f, args=('P',))
  16.    p.start()
  17.  
  18.    ## sleep for 5 seconds and terminate
  19.    time.sleep(5.0)
  20.    p.terminate()
  21.    p.join() 
Dec 17 '10 #2
dwblas
626 Expert 512MB
You can also use subprocess if running a separate program file. It would be something along these lines.
Expand|Select|Wrap|Line Numbers
  1.       proc = subprocess.Popen(program_to_run) ## may or may not require shell=True
  2.       time.sleep(sleep_secs)
  3.       os.kill(proc.pid, signal.SIGUSR1) 
Dec 17 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: JD | last post by:
This is another Python problem, I think might be unrelated to the earlier bug I found, and eventually figured out how to report it to Sourceforge. This is related to a question I have about...
2
by: Patrick Hatcher | last post by:
Running a perl script against my dev server (pg 7.3.4) that currently runs fine on the production server. And for some reason Pg always seems to hang during the process (see below for Top print...
3
by: JTF | last post by:
Whenever I start an application from ASP.NET, the exe hangs, with Task manager showing no cpu time. Every exe I've tried hangs in the same way (notepad, cmd, ms access). What runs is a .net exe...
1
by: Scott | last post by:
I am trying to write an asp.net web page that will spawn a third party .exe file and return the results back to my asp page. I am able to write a vb.net program that will do this just fine. I...
3
by: silverburgh.meryl | last post by:
Hi, Can you please tell me how Use python to process XML file? The example I find is build a DOM, but I just need to do it in SAX based, how can I do that? For example, I have a xml file like...
3
by: Thomas Dybdahl Ahle | last post by:
Hi, I'm writing a program, using popen4(gnuchess), The problem is, that gnuchess keeps running after program exit. I know about the atexit module, but in java, you could make a process a daemon...
2
by: test3 | last post by:
Hello folks, I'm using System.Diagnostics.Process to start a thirdparty program (that works perfectly when started via command line). I'm using Process.StandardOutput to get the output of the...
5
by: Saya | last post by:
Hi Folks, I have now spend app. 3 days to get the below scenario to work, but can not get there! ..Net version = 2.0.50727 Windows version = Microsoft Windows = Windows Server 2003 Now I...
0
by: eso40043 | last post by:
Hello, due to a memory leak (bug, I guess) in pyraf(or rather in IRAF) I have to fork an iterative process that goes through hundreds of image frames and does unspeakable things to them. In the...
1
by: Salim Fadhley | last post by:
Does anybody know of a python module which can do process management on Windows? The sort of thing that we might usually do with taskmgr.exe or process explorer? For example: * Kill a process...
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
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...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.