I have a python toolbox tool that downloads multidimensional rasters via API calls. The tool has a checkbox to allow the user to merge the downloaded rasters. If this box is checked, the tool merges those rasters using the merge multidimensional rasters tool. If I then try to run the tool again, intending to download and overwrite the individual rasters again, the raster download fails because the existing rasters are "being used by another process". The other process is the merge operation which is long finished at that point. If the merge checkbox remains unchecked, I can re-run the tool as many times as I like without a problem. None of the input or output rasters are in geodatabases
The only thing that seems to release the lock is closing and opening ArcGIS Pro. I have tried the following without any luck:
- changing the scratch workspace
- adding arcpy.env.overwriteOutput = True to my script
- putting the merge operation in another script that gets loaded in the main python toolbox
- executing the merge inside a "with" statement: with arcpy.EnvManager(workspace=xyzxy)
- clearing the cache, refreshing the map, saving the project
def execute(self, parameters, messages):
"""The source code of the tool."""
paramdict={}
for x in range(0,len(parameters)):
p=parameters[x]
paramdict[p.name]=p
inputlist=[
"--url" , paramdict["baseUrl"].valueAsText,
"--orders",paramdict["ordersToDownload"].valueAsText,
"--runs" , paramdict["orderRuns"].valueAsText,
"--apikey" , paramdict["apikey"].valueAsText,
"--location" , paramdict["baseFolder"].valueAsText,
"--verbose"]
message_queue = queue.Queue()
files=[]
folders=[]
# download files using api call
cda_download(inputlist,message_queue,module=arcpy, files=files, folders=folders)
if paramdict["addToMap"].value==True:
messages.addMessage("Merging rasters and adding to map")
arcpy.AddMessage(folders)
arcpy.AddMessage(files)
outfile = paramdict["outRas"].valueAsText
files_to_merge=files
try:
arcpy.md.MergeMultidimensionalRasters(files_to_merge,outfile)
except Exception as ex:
messages.addMessage("Something went wrong merging\n")
messages.addMessage(f"input files: {files_to_merge} \noutput file: {outfile}\n")
messages.addMessage(ex)
arcpy.AddMessage("\n===========\nFor Info. Messages produced during downloading:\n")
print("\n===========\nFor Info. Messages produced during downloading:\n")
while not message_queue.empty():
msgq=message_queue.get()
arcpy.AddMessage(msgq)
print(msgq)
any thoughts on how to resolve this?