저는 많은 pool.map을 연구했으며 여전히 내 문제를 암시하는 내용을 찾을 수 없습니다.Python Pool.map() - 서버에서 로컬로 작동하지 않습니다.
모든 .py 파일에 if __name__ == '__main__'
이 있습니다. 나는 import multiprocessing
을 포함하고있는 각각의 .py에 freeze_support()
을 갖고 있는데, 나는 아직도 일어나고있는 일에 대해 상실하고있다. 동일한 코드 결과로 freeze_support()
을 내 코드로 옮겼습니다.
스크립트 A는 스크립트 B를 호출하고 스크립트 B는 스크립트 C (다중 처리가 발생하는 곳)를 호출합니다. 로컬에서는이 시나리오가 완벽하게 작동하지만 Windows Server 2008 컴퓨터에로드하면 이상한 일이 일어나기 시작합니다.
서버에서 나는 인터프리터에 인쇄 된 첫 번째 iterable을 볼 수 있지만 스크립트 B로 돌아가서 처리를 계속합니다.
if not arcpy.Exists(MergedDataFC):
ScriptC.intersect_main(input1, input2)
if not arcpy.Exists(MergedDataSHP):
shpList = arcpy.ListFields(*.shp) # output of multiprocess
# Merge all shapefiles into single shapefile
# Being executed before the multiprocess finishes all 52 items
스크립트 C 코드 : 온
모든 데이터
import multiprocessing as mp
def intersect_main(input1,input2):
try:
mp.freeze_support()
# Create a list of states for input1 polygons
log.log("Creating Polygon State list...")
fldList = arcpy.ListFields(input1)
flds = [fld.name for fld in fldList]
idList = []
with arcpy.da.SearchCursor(input1, flds) as cursor:
for row in cursor:
idSTATE = row[flds.index("STATE")]
idList.append(idSTATE)
idList = set(idList)
log.log("There are " + str(len(idList)) + " States (polygons) to process.")
log.log("Sending to pool")
# declare number of cores to use, use 1 less than the max
cpuNum = mp.cpu_count() -1
# Create the pool object
pool = mp.Pool(processes=cpuNum)
# Fire off list to worker function.
# res is a list that is created with what ever the worker function is returning
log.log ("Entering intersectWork")
res = pool.map((intersectWork(input1, input2, idSTATE)),idList)
pool.close()
pool.join()
# If an error has occurred report it
if False in res:
log.log ("A worker failed!")
log.log (strftime('[%H:%M:%S]', localtime()))
raise Exception
else:
log.log("Finished multiprocessing!")
log.log (strftime('[%H:%M:%S]', localtime()))
except Exception, e:
tb = sys.exc_info()[2]
# Geoprocessor threw an error
log.log("An error occurred on line " + str(tb.tb_lineno))
log.log (str(e))
def intersectWork(input1,input2, idSTATE):
try:
if idSTATE == None:
query = "STATE IS NULL"
idSTATE = 'pr'
else:
query = "STATE = '" + idSTATE + "'"
DEMOlayer = arcpy.MakeFeatureLayer_management(input1,"input1_" + idSTATE)
log.log (query)
arcpy.SelectLayerByAttribute_management(DEMOlayer,"NEW_SELECTION",query)
# Do the Intersect
outFC = r'C:/EclipseWorkspace' + '/INTER_' + idSTATE.upper() + '.shp'
strIntersect = str(DEMOlayer) + ";" + str(input2)
arcpy.Intersect_analysis(strIntersect, outFC, "ALL", "", "LINE")
return True
except:
# Some error occurred so return False
log.log(arcpy.GetMessage(2))
return False
if __name__ == '__main__':
intersect_main(input1, input2)
스크립트 편집 C.
스크립트 B 코드에 대한 목록 (51 개) 기타 항목이 있습니다 서버는 로컬로 저장되며 네트워크 처리를 거치지 않습니다.