Python causing schema lock on aprx

190
2
01-11-2022 09:26 AM
TylerT
by
Occasional Contributor

More often than not, python seems to be locking up my aprx after executing scripts.  Opening ArcGIS Pro following script execution results in a schema lock.  My script deletes the aprx as recommended but is there something else I need to do.  Typically, I have not been saving the aprx so the aprx.save() is usually omitted.  The scripts are ran outside of ArcGIS Pro in a standalone Jupyter Notebook environment.

The following snippet is recommended in the documentation:

 

aprx = arcpy.mp.ArcGISProject(<PATH>)
mp = aprx.listMaps(<MAP NAME>)[0]
<DO SOMETHING>
aprx.save()
del aprx

 

I'm wondering if the following context manager would work better, but am not seeing anything in the documentation. 

with arcpy.mp.ArcGISProject(<PATH>) as aprx:
    mp = aprx.listMaps(<MAP NAME>)[0]
    <DO SOMETHING>
    aprx.save()

Thank you,

Tyler

0 Kudos
2 Replies
DanPatterson
MVP Esteemed Contributor

If you close your notebook, does the lock go away?

If you tried the "with" context manager approach, did you notice any difference?

I suspect it may be the "do something" section the persists the lock


... sort of retired...
0 Kudos
TylerT
by
Occasional Contributor

All,

After some more experimenting, it seems the del aprx doesn't fully release the lock, however, once the python kernel is stopped the lock is released.  So, I'm getting into the habit of stopping or restarting the kernel should I need to run a series of scripts or GUI operations.  

Tyler

0 Kudos