ArcCatalog(10.5.1)/ArcGIS Server (10.6.1) crash when running arcpy script

279
2
01-10-2019 09:29 AM
HarshaPerera
New Contributor

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

0 Kudos
2 Replies
TimGunn
New Contributor

I've had similar problem with a python script published as a geoprocesssing service to ArcGIS Server 10.6. It runs fine as a standalone script or from a tool within Pro. However, the use of the LayerFile is causing my GP service to crash on Server.

0 Kudos
MauricioCastro
New Contributor

I had the same problem, the symptoms were #1 it weren't reaching further code after using the connection file to the arcgis server (like the CreateMapSDDraft or the UploadServiceDefinition_server calls) so I came to the conclusion something was wrong in the server connection file. #2 the connection files worked fine in Arcmap which was really confusing, then I noticed it worked there but was asking to accept and invalid server certificate. #3 No logs were added to the ArcGIS server, like Arcpy was unable to reach it. So, I was using the http site url for connections but I remembered we enabled https in the server recently as part of an upgrade to 10.7.1. The server's certificate was invalid, once we solved that we were able to publish successfully to that server. I also had to register the SQL Server database in the server for it to work because we had changed the IPs recently (in Registered Databases)

0 Kudos