Locked File issue in arcpy loop

805
4
Jump to solution
11-21-2021 09:39 PM
YonasKassa
New Contributor II

Hi Everyone,

I am using the multiprocessing to generate multiple watershed. Each processor uses certain sets of watershed outlet points and the "for loop" to: (1) first generate the snap pour point using-- arcpy.sa.SnapPourPoint() , (2) save the resulted raster, (3) generate and save the watershed which uses the snap pour raster as input , 4) delete the snap pour raster and the watershed raster using arcpy.Delete_management (). The watershed deleted without a problem but the snap pour rasters are locked and can not be deleted. How can i release the lock and delete the file during each run of the loop without closing the program? I am using python 2.7. Many thanks,

Jonas  

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
YonasKassa
New Contributor II

I believe there is always a way around to address such coding issue. It seems i have solved my problem by working on gdb instead of file directory. My initial code used file directories for the work and scratch space. I have changed that to gdb. The rest of the code is the same, for each loop run it generates Snap pour and watershed rasters save them now in gdb, get the watershed area using curse and then delete the curse (del curse) and the rasters using arcpy.Delete_management, repeat the loop for a different snap point.

View solution in original post

0 Kudos
4 Replies
DanPatterson
MVP Esteemed Contributor

Do you have ....

arcpy.env.overwriteOutput = True

set in your script?


... sort of retired...
0 Kudos
YonasKassa
New Contributor II

Hi Dan, Thank you. Yes, i have arcpy.env.overwriteOutput = True declared outside the loop. But still, the Snap pour raster is locked, even if the Watershed raster generated from it is not locked. I tried to generate the Snap pour raster through a function called within the loop. That way, i thought when the function return the raster it would release the lock. Saving the raster alone is not releasing it. The lock on the Snap pour raster is very persistent.      

0 Kudos
DanPatterson
MVP Esteemed Contributor

There isn't much that you can do about a python lock, if that is the cause


... sort of retired...
0 Kudos
YonasKassa
New Contributor II

I believe there is always a way around to address such coding issue. It seems i have solved my problem by working on gdb instead of file directory. My initial code used file directories for the work and scratch space. I have changed that to gdb. The rest of the code is the same, for each loop run it generates Snap pour and watershed rasters save them now in gdb, get the watershed area using curse and then delete the curse (del curse) and the rasters using arcpy.Delete_management, repeat the loop for a different snap point.

0 Kudos