2

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')
  • If you delete all of the code represented by your "... code ..." line (ie, the script includes ONLY what you've posted in the first version above), does the problem still occur? If so, then post only that code, exactly as is with no bits missing. Ie, post the smallest, simplest COMPLETE code for which the problem occurs (by editting your original post). If the problem does NOT occur without that code, then you need to include that code in your post. – Son of a Beach Oct 18 '19 at 5:29
  • Actually I dont think the code will help. I just tried to hardcode with a feature class that fails and it still fails. See my edit. – Maw Oct 18 '19 at 6:31
  • You refer to "files" but your connection is to an Enterprise geodatabase, so the "files" are really "tables". SQL is a language common to dozens of RDBMS - Are you using Microsoft SQL Server? If so, which release? – Vince Oct 18 '19 at 10:44
  • Ye thats right Vince. Its not a file and it can be a bit confusing that I call it for a file in the example of the script. Did not think about that. We are using Microsoft SQL Server 2014 (12.0.5590.1 ??). – Maw Oct 18 '19 at 10:54
1

Not sure if you figured out the cause yet, but I had similar issues when attempting to perform back to back geoprocessing tasks on the same data. ArcPy would attempt to process the second task before the first task had properly released its data lock. My solution was to pause the script between tasks with time.sleep(1). This allowed the first task to properly release the lock before proceeding to the next geoprocessing task. Might be worth a try on your end to see if the behavior changes.

| improve this answer | |
0

That was my first thought but script only release the lock if you quit the process. It did not help with sleep, disconnect all user etc. I found a way to fix the problem. Now I use subprocess to clip the feature class and a while not loop with arcpy.TestSchemaLock to wait until the clip process is finished before the script deletes the "in feature class".


I used subprocess.Popen. Found out that if I use subprocess.call I dont have to use the while loop for testschemalock because when use subprocess.call the scripts wait until the subprocess is done before it run the delete function.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.