arcpy.mp.ArcGISProject .aprx lock issue

385
6
03-20-2024 10:09 AM
JackC
by
New Contributor II

Hey Everyone,

I wrote a python script for a client that extracts a project template to a new folder, manipulates the data and layouts in that new project, creates PDFs, saves a copy of that extracted project file with the current month/year, and then tries to delete the extracted project. The deletion always fails, and my VS Code terminal or the GP tool I built the script for says it's because the project is open somewhere.

I have tried deleting every variable that references the project, maps, layouts, elements, all arcpy.mp classes for that matter, and it still always fails.

Even if I close Pro where I ran the GP tool, or close VS Code where I was debugging the script and then go to File Explorer to delete the extracted Pro project, File Explorer says I can't because the file is open somewhere, which it is not when looking at my computer. 

Has anyone encountered this, and/or know a way around it?

Thanks!

- Jack C

0 Kudos
6 Replies
Eugene_Adkins
Occasional Contributor III

I have no experience with the workflow you’re referencing but I wonder if the project has any feature services as a data source? Until the service is shutdown I would guess an error similar to this would occur. This is only a complete guess.

0 Kudos
JackC
by
New Contributor II

Hey Eugene,

I appreciate the reply. Currently, all data sources reference file geodatabase feature classes. When this issue first occurred, I checked Task Manager's Processes and Details panes to see if anything related to Pro was still active and did see ArcGISPro.exe in the Details pane, even though Pro was not open. I found that odd, but then didn't see it again, even though the issue persisted.

0 Kudos
MErikReedAugusta
Occasional Contributor III

My understanding of the lock behavior is that lock files are created and stored somewhere in the directory for GDBs, and I would assume something similar is happening for the APRX.  If that lock file isn't properly cleaned up, then the software assumes someone somewhere is using it, even if they aren't.

It's like seeing antibodies and assuming the presence of a disease, even if the antibodies are just left behind and the disease was eradicated.

0 Kudos
Robert_LeClair
Esri Notable Contributor

So there was an enhancement request, ENH-000140298 - Add a method to the arcpy.mp.ArcGISProject() object that will close the project and release locks held by a script.  But it was marked as "will not be addressed."  The explanation was "Locks on a project file can be eliminated by either closing the Python shell (vs the script editor) or by calling del on the appropriate variables. The method has little value when run in a script outside of the application and also inside the application."

JackC
by
New Contributor II

Hey Robert,

Thanks for the reply and info about that enhancement request. The problem is, however, that I do delete all appropriate variables in an attempt to remove a lock, and it still doesn't work. I decided to switch from Extract Package to aprx.saveACopy(). Somehow when I run my GP tool with Pro open, even though the project it's working on is not open in Pro, I can't delete it unless I close all instances of Pro. This is even if I delete all variables referencing class objects that are part of arcpy.mp.ArcGISProject .

0 Kudos
Robert_LeClair
Esri Notable Contributor

Certainly Jack - happy to assist where I can.  Have you contacted Esri Support Services to see if they can assist you further?

0 Kudos