Hello, all.I've got a python code that I'm trying to get ready for use with multiprocessing (using StacyR's helpful code here). I've got a list of roads in an area threatened by wildfire, and I'm trying to see which are the most critical to protect by seeing how many residents will loose access to critical facilities if a given road is set as non-traversable. So, I'm running through a list of the pertinent roads (around 20,000, which is why I'm trying to get multiprocessing to work), and in each run, I set the selected road as non-traversable, solve the closest facility problem, and generate a summary statistics table to determine the number of pop who no longer have access.The code below is the function that is called for each road in the list of 20,000. It solves the analysis, does some calculations, generates a summary statistics table, and writes it out to a workspace. It all works perfect if I run it as an in-process script tool in ArcMap, but when I try to run it through the command line, or not in process (out process?) through ArcMap, it fails when I try to use MakeTableView (in the 4th line) to get the information from the closest facilities layer routes. Does anyone have any idea what could be causing this?EDITI forgot to note: when it hits that line, it says path\analysis_layer.lyr\Routes does not exist (where path\analysis_layer.lyr is the path and name of the closest facility layer saved to disk), even though it just used that layer file to solve the closest facility problem in the previous line.END EDIT
def findRoadImportance(current_road,analysis_layer,table_view,OWS):
arcpy.UpdateAnalysisLayerAttributeParameter_na(analysis_layer, "Drop_list", "Dropped Road", current_road)
arcpy.Solve_na(analysis_layer,"SKIP", "TERMINATE", "")
arcpy.MakeTableView_management(analysis_layer + "\\Routes", table_view, "", "", "Name Name VISIBLE NONE;Total_Length Total_Length VISIBLE NONE")
arcpy.DeleteRows_management(analysis_layer + "\\Routes")
arcpy.AddField_management(table_view, "Pop", "LONG")
arcpy.AddField_management(table_view, "PW","DOUBLE")
arcpy.CalculateField_management(table_view, "Pop", "getPop( !Name!)", "PYTHON_9.3", "def getPop(field):\\n return field[:field.find(\" \")]")
arcpy.CalculateField_management(table_view,"PW", "calcMean( !Pop!, !Total_Length!)", "PYTHON_9.3",
"def calcMean(field1,field2):\\n return field1 * field2")
out_table = OWS + "\\" + str(int(current_road)) + "_result.dbf"
arcpy.Statistics_analysis(table_view, out_table, [["Pop","SUM"],["PW","SUM"]])
arcpy.AddField_management(out_table, "Road_ID","LONG")
arcpy.CalculateField_management(out_table, "Road_ID", current_road)
arcpy.AddMessage(" Output table written with drop road ID %s..."%(current_road))
return
Also, I'm wondering if multiprocessing will actually work with this approach. Since I'm using UpdateAnalysisLayerAttributeParameter to iteratively set roads as non-traversable in the same underlying Closest Facilities layer, can this truly be split apart between cores? Or will the results be messed up because changes made in the underlying layer by one job will influence the results in other jobs?Thanks for any help you all can give,matt