我发现尝试将多个线程/核心保存并修改一个文件夹中的栅格时遇到INFADI错误。为输出的每个任务分配一个子文件夹似乎可以解决此问题。我认为问题与与栅格关联的外围文件(例如“ info”文件夹)的多次读/写有关。我现在还采用以下预防措施:
import arcpy,multiprocessing,random
def run(foo,c):
tempFolder = os.path.join("Z:/temp/",'temp_%s'%(str(c)))
if not os.path.exists(tempFolder): os.mkdir(tempFolder)
arcpy.env.scratchWorkspace = tempFolder
arcpy.env.Workspace = tempFolder
# create unique object in memory, run task, then delete unique object in memory
tempMem = str(rnd)
try:arcpy.Delete_management(tempMem)
except:pass
<tasks> #output to appropriate subfolder
arcpy.Delete_management(tempMem)
if __name__ == '__main__':
cores = 3
pool = multiprocessing.Pool(cores)
count = 0
for foo in bar:
pool.apply_async(run,(foo,c))
count +=1
pool.close()
pool.join()