ArcGIS Server arcpy.mapping service hanging with ESRI basemap in mxd

Discussion created by trenthardy on May 18, 2011
Latest reply on May 11, 2012 by geodan7
I am attempting to create an ArcGIS Server geoprocessing service that exports a map. The service runs a python script that uses the arcpy.mapping module to modify map extent, visible layers, layout elements, etc. of an existing mxd, then export the map. I have run into a problem, though, if the mxd has one of the ESRI hosted basemaps and I run the script through the service. If I run the script locally on the server, it works fine. If I run the script through the service, the code hangs when I call ListDataFrames.

mxDoc = arcpy.mapping.MapDocument(r'path\to\mxd')

def setVisibleLayers(mxDoc):
    dataFrame = arcpy.mapping.ListDataFrames(mxDoc)[0] #code hangs here

The code will sit here until the service reaches its timeout, at which point it logs an error, but then, strangely, it completes (usually, though not always). The job status shows failed, but the map gets exported. Below is the message output from ArcGIS Server:

Job ID: je327da53fea846d184109dd21edd85d4

Job Status: esriJobFailed

Job Messages:

esriJobMessageTypeInformative: Submitted.
esriJobMessageTypeInformative: Executing...
esriJobMessageTypeInformative: Executing (MapPrint): MapPrint Landscape8x11 -12457810 4955286 -12457587 4955538 0 # "a title" "a subtitle" "some comments" pdf A1234
esriJobMessageTypeInformative: Start Time: Wed May 18 08:38:41 2011
esriJobMessageTypeInformative: Running script MapPrint...
esriJobMessageTypeInformative: Setting Visible Layers
esriJobMessageTypeError: Failed.
esriJobMessageTypeError: Execution of job je327da53fea846d184109dd21edd85d4 failed because of crash or termination of the server object.
esriJobMessageTypeInformative: Setting Extent
esriJobMessageTypeInformative: Setting Layout Text
esriJobMessageTypeInformative: Adding basemap
esriJobMessageTypeInformative: Exporting Map
esriJobMessageTypeInformative: Exported E:\arcgisserver\arcgisoutput\PrintableMap\A1234_130573342519.PDF
esriJobMessageTypeInformative: Completed script MapPrint...
esriJobMessageTypeInformative: Succeeded at Wed May 18 08:43:51 2011 (Elapsed Time: 5 minutes 10 seconds)

What more is curious is that in a separate log where I have timestamps, the code will get to the ListDataFrames function quickly and sit there for the 5 minute service timeout. Then in a fraction of a second, the rest of the script will be logged and the map will be generated. This could be related to the logger, but the create timestamp of the exported file coincides with the timestamp in the log for when it says it exports.

Any ideas?