Trying to create a geoprocessing service on ArcGIS for Server 10.3 to do some routing on a networkx graph. The service only works on the first call. It fails on subsequent calls. I note this because when I restart the service and make a fresh call, I get expected results.
Below is the published script via a toolbox.
import os
import networkx as nx
import arcpy
LOCAL_WS = r"C:\inetpub\wwwroot\src.gdb"
EDGES_FC = os.path.join(LOCAL_WS, "EDGES")
MAINS_FC = os.path.join(LOCAL_WS, "MAINS")
M = nx.MultiGraph()
edge_fields = ["LOC1", "LOC2", "CABLE"]
with arcpy.da.SearchCursor(EDGES_FC, edge_fields) as ecur:
for erow in ecur:
loc1 = erow[0]
loc2 = erow[1]
cable = erow[2]
# Add the segment to the graph
M.add_edge(loc1, loc2, key=cable)
def checkIsolated(a_node, z_node):
try:
paths = nx.dijkstra_path(M, source=a_node, target=z_node)
return "HAS PATH"
except nx.NetworkXNoPath:
return "NO PATH"
except:
return "FAILED ROUTING"
if __name__ == "__main__":
# Isolation Test
a_loc = arcpy.GetParameterAsText(0)
z_loc = arcpy.GetParameterAsText(1)
checkResult = checkIsolated(a_loc, z_loc)
arcpy.SetParameterAsText(2, checkResult)
This is the error logged by ArcGIS for Server:
File "E:\arcgisserver\directories\arcgissystem\arcgisinput\FindIsolated.GPServer\extracted\v101\arcgisservermxds\NetworkXTools.tbx#FindIsolated.py", line 11, in File "E:\Python27\ArcGISx6410.3\lib\site-packages\networkx\__init__.py", line 128, in import networkx.drawing File "E:\Python27\ArcGISx6410.3\lib\site-packages\networkx\drawing\__init__.py", line 6, in from . import nx_pydot File "E:\Python27\ArcGISx6410.3\lib\site-packages\networkx\drawing\nx_pydot.py", line 27, in from pkg_resources import parse_version File "E:\Python27\ArcGISx6410.3\lib\site-packages\pkg_resources\__init__.py", line 50, in from pkg_resources.extern import six File "E:\Python27\ArcGISx6410.3\lib\site-packages\pkg_resources\extern\__init__.py", line 44, in load_module mod = sys.modules[extant] AttributeError: 'NoneType' object has no attribute 'modules' Failed to execute (FindIsolated).
The networkx library was installed into in the 64-bit version of the Python on Windows 2008 Server (that comes bundled with ArcGIS for Server). IIS is our web server.
Any thoughts?
(My hope is to have an active web service holding the networkx graph and not have to recreate it everytime I want to route some nodes.)