How to know if a process is still running in Python? -
i have been doing research on this, questions (in newbie understanding) seem address how figure out if program running, not python itself.
so, working on code generates buffers around set of lines in shapefile. batch process involves20 shapefiles , 4000 lines inside them. process taking long time, , starting wonder if working. use print statements keep track of progress of code, in case calling arcgis function print statement can write 1 after lines have been processed, not while it's still running.
is there way find out if process still going on (other checking task manager see if it's frozen)?
crazy way of doing thought of (no idea if possible): thinking of writing in txt file every x number of minutes long script hasn't finished running.
thanks!!!!
my code:
def buffer30m(self,inputfile,outputbuffer, size): arcpy.buffer_analysis(inputfile,outputbuffer,size,"full","round","none","#") thelist=os.listdir(ssflinespath) #read files in folder os.mkdir(ssflines+"ssfbuffers" #create folder output ssbuff=ssflinespath+"ssfbuffers/" #select folder destination try: size=30 thefile in thelist: #identify each file thefilename, thefileextension = os.path.splitext(thefile) #break file name if (thefileextension==".shp"): #identify shapefiles thelines=ssflines+thefile ##generate 30m buffer around lines thebuffer=ssfbuff+thefilename+"_buff30.shp" thestepbuffer.buffer30m(thelines,thebuffer,size) print "ssf buffer done" except exception theerror: print "error ssf forest area calculation" print theerror
update partial solution, complete code , new issue:
i applied qwwqwwq's suggestion, works great function mentioned before. thing when run rest of script (what showed before part of wouldn't have read much) of other functions don't work.
here complete script:
class stepbuffer: def getpairinfo (self, mainfile, sourcefile, wantfields, ssf): fields= wantfields #fields keep ##extract info , add main table if ssf==false: grhe_proj.getfieldinfo(mainfile,sourcefile,"pair", "pair", fields) elif ssf==true: grhe_proj.getfieldinfo(mainfile,sourcefile,"sampleid", "sampleid", fields) def buffer30m(self,inputfile,outputbuffer, size): arcpy.buffer_analysis(inputfile,outputbuffer,size,"full","round","none","#") def areabuff (self,inputfile, outputtable): arcpy.calculateareas_stats(inputfile,outputtable) def areaforest (self,bufferfile,forestfile, outputtable, ssf): if ssf==false: arcpy.tabulateintersection_analysis(bufferfile,"pair",forestfile,outputtable,"type","#","#","hectares") elif ssf==true: arcpy.tabulateintersection_analysis(bufferfile,"sampleid",forestfile,outputtable,"type","#","#","hectares") thelist=os.listdir(ssflinespath) #read files in folder os.mkdir(ssflines+"ssfbuffers" #create folder output ssbuff=ssflinespath+"ssfbuffers/" #select folder destination try: size=30 thefile in thelist: #identify each file thefilename, thefileextension = os.path.splitext(thefile) #break file name if (thefileextension==".shp"): #identify shapefiles thelines=ssflines+thefile ##generate 30m buffer around lines t = threading.thread(target=thestepbuffer.buffer30m, args=(thelines,thebuffer,size)) t.start() while (t.is_alive()): time.sleep(2) ## sleep don't execute print statement print "i'm alive!" print "ssf buffer done" ##calculate area of buffer tableareabuff=outputtables+thefilename+"_area_buffers.dbf" thestepbuffer.areabuff(thebuffer,tableareabuff) print "ssf area buffer done" ##calculate area of forest inside buffer tableareafor=outputtables+thefilename+"_area_forest.dbf" thestepbuffer.areaforest(thebuffer,forestpath,tableareafor,true) print "ssf area forest done" ##add info of area of buffer buffer layer thestepbuffer.getpairinfo(thebuffer,tableareabuff, "f_area",true) ##add info of area of forest within buffers buffer layer thestepbuffer.getpairinfo(thebuffer,tableareafor,["area","percentage"],true) print thefilename+"done" except exception theerror: print "error ssf forest area calculation" print theerror theerrorfile.writelines(format(theerror)+"\n")
specifically, error appears when gets :
thestepbuffer.areaforest(thebuffer,forestpath,tableareafor,true)
producing error:
arcgisscripting.executeerror: traceback (most recent call last): file "c:\program files (x86)\arcgis\desktop10.1\ arctoolbox\scripts\calculateareas.py", line 76, in <module> setupcalcareas() file "c:\program files (x86)\arcgis\desktop10.1\arctoolbox\scripts\calculateareas.py", line 31, in setupcalcareas calculateareas(inputfc, outputfc) file "c:\program files (x86)\arcgis\desktop10.1\arctoolbox\scripts\calculateareas.py", line 55, in calculateareas cnt = utils.getcount(inputfc) file "c:\program files (x86)\arcgis\desktop10.1\arctoolbox\scripts\ssutilities.py", line 502, in getcount return int(countobject.getoutput(0)) file "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\arcobjects\arcobjects.py", line 986, in getoutput ... (truncated) return convertarcobjecttopythonobject(self._arc_object.getoutput(*gp_fixargs(args))) ... (truncated) file "c:\users\noelia volpe\dropbox\project\analisis\python_codes\scripts\movementpref\volpe_project_v2.py", line 464, in <module> thestepbuffer.areabuff(thebuffer,tableareabuff) file "c:\users\noelia volpe\dropbox\project\analisis\python_codes\reusable\movement_preferences.py", line 58, in areabuff arcpy.calculateareas_stats(inputfile,outputtable) file "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\stats.py", line 1564, in calculateareas raise e
does know might source of error? thanks!
i try using multithreading:
import threading import time t = threading.thread(target=thestepbuffer.buffer30m, args=(thelines,thebuffer,size)) t.start() while (t.is_alive()): time.sleep(2) ## sleep don't execute print statement print "i'm alive!"
your thread execute function thestepbuffer.buffer30m
, , control thread monitor thread make sure still executing target function, executing print
statement let know well.
Comments
Post a Comment