I have a Python script that is looping through a list of feature classes stored in a config file. It is exporting the metadata for each feature class using the methodology in the answer posted to Creating table containing all filenames (and possibly metadata) in File Geodatabase?
The script runs as expected, however, when performance testing I'm finding that the first time the MetadataImporter_conversion command is executed, it is taking approximately 60 seconds to complete. On subsequent iterations the same command takes less than a second to complete.
I have tried re-ordering the feature classes within the config file to test if the issue is being caused by a particular feature class, but it had no impact. The first feature class in the list takes 60 times longer to process than the ones that follow.
Ultimately this script will be incorporated into a Geocortex workflow, so I'm trying to make it as efficient as possible so that the user doesn't have to hang around waiting for the results to be returned.
This is a snippit of the code I'm using:
# ---------------------------------------------------------------------------
def CreateDummyXMLFile():
filepath = r"e:\temp\tmpXML.xml" # This path is for testing purposes only
with open(filepath, "w") as f:
f.write("<metadata />")
return filepath
# ---------------------------------------------------------------------------
# ---------------------------------------------------------------------------
def GetElementText(tree, elementPath):
"""Returns the specified element's text if it exists or an empty
string if not."""
element = tree.find(elementPath)
return element.text if element != None else ""
# ---------------------------------------------------------------------------
# ---------------------------------------------------------------------------
def GetMetadataElementTree(dataset):
"""Creates and returns an ElementTree object from the specified
dataset's metadata"""
xmlfile = CreateDummyXMLFile()
arcpy.MetadataImporter_conversion(dataset, xmlfile)
tree = ElementTree()
tree.parse(xmlfile)
os.remove(xmlfile)
return tree
# ---------------------------------------------------------------------------
for aIntersect in ListOfFeatureClasses:
xmlfile = CreateDummyXMLFile()
tree = GetMetadataElementTree(aIntersect)
aTitle = GetElementText(tree, "dataIdInfo/idCitation/resTitle") # Title
aPubDate = GetElementText(tree, "dataIdInfo/idCitation/date/pubDate") # Publication Date
print " Title: {}".format(aTitle)
print " Date: {}".format(aPubDate)
del tree
Processing times with baam feature class as the first item in the list:

Processing times with esa_c feature class as the first item in the list:

Can someone explain this behaviour or replicate it?
Testing on my personal PC running arcgis-10.6 has not been able to replicate the issue. Would be interested to know if this issue is related to arcgis-10.3 or perhaps just isolated to my work PC.