#Multiple_buffer.py def doBuffer():# empty brackets as no arguments are passed ### # whatever your buffer code was all goes here - all indented...
import arcpy from arcpy import env #import subprocess # no longer required import Multiple_buffer # Local variables: env.workspace = "C:\\Users\\Claire Parsons\\Documents\\Projects\\site_Selection_Testing\\Clip" fcs = arcpy.ListFeatureClasses() clipout = "_clip.shp" clipFeature = "C:\\Users\\Claire Parsons\\Documents\\Projects\\site_Selection_Testing\\Clip\\East_Mids.shp" for fc in fcs: dsc = arcpy.Describe(fc) arcpy.Clip_analysis(dsc.catalogpath, clipFeature, dsc.catalogpath.rstrip(".shp") + clipout,"") Multiple_buffer.doBuffer() # calling the doBuffer module in Multiple_buffer - this will run the contents of the def statement (basically your Multiple_buffer script)
def spawn_function(pythonExe, # exe of python workerScript, # script that does the work (path to .py file) inFC,# source feature class 1st variable in script scratchWrksp, # scratch workspace 2nd variable in script, etc... count # Thread ID number defined by user ): p = subprocess.Popen([pythonExe, workerScript, str(inFC), str(scratchWrksp), str(count) ],\ cwd=os.path.dirname(scratchWrksp),\ shell=False,\ stdout=subprocess.PIPE,\ stderr=subprocess.PIPE) return p
if __name__ == "__main__": pList = [] processCount = (int(os.environ["NUMBER_OF_PROCESSORS"]) - 1) # to account for main thread pythonExe = os.path.join(sys.exec_prefix,'python.exe') for r in range(0,processCount): pList.append(spawn_function(ALL THE VARIABLES)) # then you have to check if the process completed
p = subprocess.Popen([pythonExe,# path to python exe workerScript, # path to script scriptVar1,... #variables as strings ],\ cwd=os.path.dirname(scratchWrksp),\ shell=False,\ stdout=subprocess.PIPE,\ stderr=subprocess.PIPE)
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.