I've written a python function that calls a tool (Import CAD to GDB) in a loop. When I run it I have seen that it hangs sometimes, and I have to force the script to quit. I am wondering if there is a way to kill the tool execution after a certain amount of time, and move on to the next item in the loop? Here is what I have so far - I've included a timer but it still hangs:
import os, arcpy, arcgisscripting, time, sys
gp = arcgisscripting.create()
def ConvertCADtoGDB(srch_dir,gdb_dir,timeout):
for dirpath, dirnames, files in os.walk(srch_dir):
for file in files:
f_name, f_ext = os.path.splitext(file)
in_dgn = dirpath+'\\'+file
out_gdb = gdb_dir+'\\'+f_name+'.gdb'
if f_ext == '.dgn':
if not os.path.isdir(out_gdb):
start = time.time()
end = start + timeout
while time.time() < end:
print 'creating',out_gdb
gp.ImportCAD_conversion(in_dgn,out_gdb,'','Explode_Complex')
time.time() < end
will calculate the time when it starts thatwhile
loop, but not continue checking it whileImportCAD_conversion
is running. – Erica Jul 10 '14 at 15:22