I created a standalone arcpy script which I then converted to a Python toolbox with the intention of publishing it as a geoprocesssing service. The script runs fine when run standalone (i.e. python scriptname.pyt). However, when I run it using ArcCatalog (10.5.1) it crashes ArcCatalog. It seems to crash at the point of exiting a function. I then tried deploying it to ArcGIS Server (10.6.1). I find that it sill crashes on this newer version of server. I have found that the problem seems to be caused by a call to the arcpy.mapping.CreateMapSDDraft method. The method works ok but as stated earlier this causes the calling function to crash on exit. Here is the code snippet that causes the problem
sddraft = os.path.join(wrkspc, servicename + '.sddraft')
newSDdraft = os.path.join(wrkspc, servicename + 'updated.sddraft')
sd = os.path.join(wrkspc, servicename + '.sd')
#Save layers to a new map document (mxd file)
mxd = arcpy.mapping.MapDocument(inputmxd)
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
sr = arcpy.SpatialReference("British National Grid")
arcpy.MakeQueryLayer_management(dbConnectionFile, featuresToPublish, "select " + columnList + " from " + featuresToPublish, "Geometry_ObjectId", 'Point', 27700, sr)
arcpy.SaveToLayerFile_management(featuresToPublish, layerfile, "ABSOLUTE")
self.messages.addMessage("Saved to layer file")
addLayer = arcpy.mapping.Layer(layerfile)
addLayer.name = servicename
arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")
mxd.saveACopy(outputmxd)
del mxd, df, addLayer
mapDoc = arcpy.mapping.MapDocument(outputmxd)
self.messages.addMessage("Saved map layer to new mxd file")
# Create draft service definition file
# This causes the calling function to crash on exit
arcpy.mapping.CreateMapSDDraft(mapDoc, sddraft, servicename, 'ARCGIS_SERVER',
serverConnectionFile, False, None, summary, tags)
del mapDoc
# Further code to stage and publish the feature service – commenting out makes no difference to the crash
Can anyone give any ideas on what might be causing the problem and how to fix/work around it?
Thanks,
Harsha