I have a script that clips 20 feature classes and delete the "clip in file" (fcin). My problem is that the script fails on 3 of the feature classes with error "May be locked by another application" when trying to delete the fcin. I have tried to use testschemalock to only delete if the script can get schema lock but no diffrent. Now I tried to disconnect all users and new workspace. Then I got an error that the fcin does not exist. Now I have no clue to what to do. I made a last try to put a while loop on the new workspace after disconnect all user but then it got stuck in the loop (arcpy.Exists) because it cant find the file (the file exist). It is only on the same feature classes on which it fails. When I check connections there is no one connected to the SQL database.
I tried to find out if there was anything wrong with the feature classes but no result. If I run the original script I have to close Python before deleting the feature class manually.
I think it was when we updated to 10.5.1 that the script started to fail.
I just tried to hardcode with a feature class that fails and it still fails. Somehow it must be the feature classes but I have no clue why.. After the script tries to delete the clip in file and fails it moves the clip in file to the root of the database. If i just use the delete.management and skip to clip the file before it works. So its possible to delete the file with ArcPy but it fails if I clip the file before.
connection = 'connectionfile.sde'
arcpy.env.workspace = connection
arcpy.env.workspace = connection + '\\' + 'map_zone2'
arcpy.Clip_analysis('clip_in_file', 'clip_file_zone2', 'clip_out_file_zone2')
arcpy.Delete_management('clip_in_file')
ERROR 000601: Cannot delete clip_in_file. May be locked by another application.
Layer in use [clip_in_file]
Failed to execute (Delete).
Failed at Fri Oct 18 08:20:32 2019 (Elapsed Time: 0,65 seconds)
Code with while loop
arcpy.Clip_analysis('clip_in_file', 'clip_file_zone2', 'clip_out_file_zone2')
print 'Disconnect all user'
arcpy.DisconnectUser(connectionsde, 'ALL')
arcpy.ClearWorkspaceCache_management()
print 'New connect'
arcpy.env.workspace = connection
arcpy.env.workspace = connection + '\\' + 'map_zone2'
while not arcpy.Exists(clip_in_file):
print 'New connect 2'
arcpy.ClearWorkspaceCache_management()
arcpy.env.workspace = connection
arcpy.env.workspace = connection + '\\' + 'map_zone2'
time.sleep(5)
print 'Delete clip in file'
arcpy.Delete_management('clip_in_file')