def Routes379(BldgList):     import arcpy     import os     import traceback     arcpy.CheckOutExtension("Network")     arcpy.env.workspace = r"C:\GIS_DATA\USERS\JIANG_C\PedestrianNavigation.gdb"     arcpy.CreateFileGDB_management("C:/GIS_DATA/USERS/JIANG_C", "379.gdb")     env.overwriteOutput = True     x = 0     for i in BldgList:         if i<>379:             arcpy.MakeClosestFacilityLayer_na("C:/GIS_DATA/USERS/JIANG_C/PedestrianNavigation.gdb/Pedestrian_Navigation/Pedestrian_Navigation_ND", "Closest_Facilities"+str(x), "Length", "TRAVEL_TO", "26400")             arcpy.MakeFeatureLayer_management("Entrance", "Entrance"+str(x)+".lyr","Bldg_No = '" + i + "'")             arcpy.AddLocations_na("Closest_Facilities"+str(x), "Incidents", "Entrance"+str(x)+".lyr", "Name Bldg_No #")             arcpy.MakeFeatureLayer_management("Entrance", "Entrance"+str(x)+"1.lyr","Bldg_No = '379'")             arcpy.AddLocations_na("Closest_Facilities"+str(x), "Facilities", "Entrance"+str(x)+"1.lyr", "Name Bldg_No #")  #solve the network analysis layer "Closest_Facilities" #if we are not able to solve the closest facility layer, make python shell pass the execution error and inform user to check out data sources #set a tuple t to store the array(i, j) and append "t" to list "ErrorBldg" #write the fialure in generating routes from building(i) to building(j) into f2 and continue the loop                         try:                 arcpy.Solve_na("Closest_Facilities"+str(x))                 Routes = arcpy.SelectData_management("Closest_Facilities"+str(x), "Routes")                 arcpy.FeatureClassToFeatureClass_conversion(Routes, "C:/GIS_DATA/USERS/JIANG_C/379.gdb", "Routes"+str(i)+"379")                 print "All the routes from Building " + str(i) + " to Building 379 have been generated."                 del Routes                 arcpy.Delete_management("Entrance"+str(x)+".lyr")                 arcpy.Delete_management("Entrance"+str(x)+"1.lyr")                 arcpy.Delete_management("Closest_Facilities"+str(x))                 try:                     arcpy.Sort_management("C:/GIS_DATA/USERS/JIANG_C/379.gdb/Routes"+str(i)+"379", "C:/GIS_DATA/USERS/JIANG_C/379.gdb/Routes"+str(i)+"379_Sort", [["Total_Length","ASCENDING"]])                     arcpy.MakeFeatureLayer_management("C:/GIS_DATA/USERS/JIANG_C/379.gdb/Routes"+str(i)+"379_Sort", "Routes"+str(i)+"379_Sort.lyr","OBJECTID <> 1")                     arcpy.DeleteFeatures_management("Routes"+str(i)+"379_Sort.lyr")                     arcpy.Delete_management("Routes"+str(i)+"379_Sort.lyr")                     print "The shortest routes from Building " + str(i)+ " to Building 379 has been generated."                 except Exception as e:                     print "Failed in sorting route for building " + str(i) + " and Building 379"                      print e.message                     del Routes                     arcpy.Delete_management("Routes"+str(i)+"379_Sort.lyr")                     pass             except Exception as e:                 print "Failed in calcuting routes between Building "+str(i)+" and Building 379. Please check network dataset sources."                 print e.message                 arcpy.Delete_management("Entrance"+str(x)+".lyr")                 arcpy.Delete_management("Entrance"+str(x)+"1.lyr")                 arcpy.Delete_management("Closest_Facilities"+str(x))                 pass             x = x+1             print str(x)     return  import arcpy BldgList = [] cursor = arcpy.SearchCursor("C:/GIS_DATA/USERS/JIANG_C/PedestrianNavigation.gdb/Entrance_Summary") for row in cursor:     a = row.getValue("Bldg_No")     BldgList.append(str(a)) del row,cursor from multiprocessing.dummy import Pool as ThreadPool pool = ThreadPool(8) results = pool.map(Routes379(BldgList),(BldgList)) pool.close() pool.join()