1

I am having an issue with schema locks while working on feature classes within a file geodatabase in ArcMap. There have been similar posts to mine (Avoiding exclusive schema lock error with ArcPy?). However, I am not working in an ArcSDE environment. I am running a Python script through the command line (Conda thru Windows if pertinent):

>>>python add_field_script.py

which calls arcpy functions WHILE ArcMap is open.

arcpy.DeleteField_management(fp_feature, ['field1', 'field2'])

I get this error (in command line console):

  File "field_mappings_config.py", line 42, in <module>
    arcpy.Delete_management(fc)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.6\arcpy\arcpy\management.py", line 4363, in Delete
    raise e
arcgisscripting.ExecuteError: ERROR 000464: Cannot get exclusive schema lock.  Either being edited or in use by another application.
Failed to execute (Delete).

My attrocious work-around is basically turn off and turn on again. I CLOSE ArcMap and rerun. Removing the fp_feature in the current map and/or collapsing feature dataset in ArCatalog without shutting off does not remove the Schema Lock.

Any ideas?

12
  • As a work around can you run the script w/o loading the layer in ArcMap?
    – artwork21
    Commented Dec 22, 2020 at 22:54
  • Hi @SonofaBeach. I am cave man. I use Atom to write my Python scripts and then I execute them through the command line. python add_field_script.py. OK, so it sounds like there is nothing programmatic I can add to my script to check and unlock gdb or feature classes? Thanks. Commented Dec 23, 2020 at 0:48
  • @SonofaBeach How about if I run the script directly in the ArcMap Python console? Not ideal, but a compromise... Commented Dec 23, 2020 at 0:54
  • I just tried it from the ArcMap Python console, and it does actually delete fields just fine. Even when deleting directly from the source feature class (not the layer) and there is a layer for that feature class currently included in the map. This was just running the arcpy.DeleteField_management() command in isolation. I have not tried running an entire script. Commented Dec 23, 2020 at 1:02
  • 1
    If you must have the layer loaded in arcmap and arcmap must be open then running your script from the python console within arcmap is your only option. You are then running your script in the same process and you should not get schema locks.
    – Hornbydd
    Commented Dec 23, 2020 at 1:09

1 Answer 1

1

ArcMap is notorious for maintaining locks on datasets that have been removed from the map. As far as I'm aware, the only way to force ArcMap to release locks is to close ArcMap completely (even then, it will sometimes fail to close, and remain running in the background with locks still in use - Task Manager is then required to kill it).

If it suits your workflow, you should be able to do this by running the Python from within the ArcMap Python console (instead of on the command line or in an IDE). I've just tried this on a feature class for which there was a layer in the map and it worked fine.

As a subsequent comment stated, this way it runs in the same process (ie, ArcMap) and therefore there is no contention for locks.

Alternatively, you can also run Python within a Model Builder model. You can use the "Calculate Value" item in a model to run a block of Python code, even if you're not interested in calculating a value.

1
  • ArcCatalog too, if you've looked at a shapefile or geodatabase and moved on the lock remains until the ArcCatalog session is ended. Even a share lock (read only) can cause an exclusive schema lock failure. When it comes to python a cursor (arcpy.SearchCursor or arcpy.da.SearchCursor and insert or update cursors) that hasn't been dismissed properly can also cause a schema lock. This grab and hold locking is worse in version 10.X than 9.X, not that I recommend using ArcGIS 9.3, it's just a general observation that locking is more persistent than it was. Commented Dec 29, 2020 at 4:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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