You can write all your functions in a simple python script to do what your doing.But if you want to use subprocessing, here is how you can use it:
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
Now you have a function that will return an instance of your subprocess. In the __main__ you call the subprocessing in a loop of some other fashion based on some requirement like number of CPUs.
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
I didn't test the code, but it will give you a general idea on how this works. You can also look at multiprocessing as well. Enjoy