Select to view content in your preferred language

Context Manager for arcpy.mp.ArcGISProject()

383
1
03-28-2025 12:21 PM
Status: Open
Labels (1)
TylerT
by
Frequent Contributor

Add Python context manager to arcpy.mp.ArcGISProject() to properly handle the setup and cleanup of the project file and resources, ensuring that they are properly managed, even if exceptions occur.  I have encountered and read about aprx locks due to Python scripts even when project object is deleted and no exceptions occurred. 

Example syntax would be:

with arcpy.mp.ArcGISProject("project.aprx") as p:
    <do something with p>
<do something after p is cleaned up>



Thanks for listening.

Tyler

1 Comment
DanPatterson

a related "with... " request

Add Context Manager Methods to ArcPy Cursor Classe... - Esri Community

context managers all around,