2016-10-04 8 views
0

Ich habe viele pool.map auf SO recherchiert und kann immer noch nichts finden, das auf mein Problem hinweist.Python Pool.map() - funktioniert lokal, auf Server schlägt fehl

Ich habe if __name__ == '__main__' in jeder .py-Datei. Ich habe freeze_support() in jedem .py, das import multiprocessing enthält, bin ich immer noch ratlos für das, was passiert. Ich habe die freeze_support() in meinem Code mit den gleichen erfolglosen Ergebnissen verschoben.

Skript A ruft Skript B, Skript B ruft Skript C auf (wo die Mehrfachverarbeitung stattfindet). Lokal funktioniert dieses Szenario einwandfrei, aber wenn ich es auf einen Windows Server 2008-Computer lade, beginnen seltsame Dinge.

Auf dem Server kann ich die erste iterable auf den Interpreter gedruckt sehen, aber es springt dann zurück zu Skript B und verarbeitet weiter. Es gibt 51 andere Elemente in der Liste für Script C.

Script B-Code:

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 

Script C-Code:

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) 

bearbeiten

werden alle Daten auf der Server wird lokal gespeichert, keine Verarbeitung über das Netzwerk.

Antwort

0

Das Problem war der vollständige Pfad zu den Daten wurde nicht ordnungsgemäß in der pool.map() auf dem Server von früheren Modulen übergeben. Ich musste alle Dateipfade unter den Importanweisungen hinzufügen. Nicht sehr elegant, aber es funktioniert.

Verwandte Themen