Select to view content in your preferred language

ArcGIS Project (.aprx) lock not released

4044
11
09-19-2018 12:26 AM
nita14
by
Frequent Contributor

Dear All,

It seems that arcpy.mp does not release the lock of the resulting (new) aprx document. The following code does create a new aprx file:

aprx_project.saveACopy(os.path.join(workspace, prefix, name_to_save))
del aprx_project

Unfortunately, the lock persists on the new .aprx file. Is there any way to remove it? Only after I close the ArcGIS Pro which I use to run the script, the lock is released.

Any hints are much appreciated!

Adam


ArcGIS Pro v.2.2.2

Tags (1)
11 Replies
DanPatterson_Retired
MVP Emeritus
# ---- try the hardway
aprx_project.saveACopy(os.path.join(workspace, prefix, name_to_save))

workspace = None
prefix = None
name_to_save = None

del prefix
del workspace
del name_to_save
del aprx_project

#---- still may fail to release the lock

#----  close your ide

are you running this in the internal python ide or an external one?

I suppose you have tried deleting the workspace, prefix and name_to_save prior to deleting the project variable as well.

finally, try closing the python window.  'del' removes the variable from the namespace only, locks can be  different beast

nita14
by
Frequent Contributor

Dear Dan.

I am running the script from ArcGIS Pro (Script tool in Toolbox), so there is no python window or ide to close.

Indeed, I tried to delete those variables as well.

The documentation clearly states that the object still has the reference to the former aprx file:

The method creates a new output project file, but the project variable continues to reference the original ArcGISProject object. It does not duplicate all the content within a project folder.

So, I reckon it is a bug in arcpy....

Best Regards!

Adam

0 Kudos
DanPatterson_Retired
MVP Emeritus

When you run it from the tool in arctoolbox and it completes, do you notice an orange exclamation mark beside the output filename, with a warning that the output filename already exists?  If so, this would mean that references to the output filename persist.  If not, then the deletion of the output filename is no longer in memory..  Worth a check

0 Kudos
nita14
by
Frequent Contributor

No warnings at all in the tool output window...

It seems that I need to get use to that 🙂

Adam

0 Kudos
DanPatterson_Retired
MVP Emeritus

This is what you get, until the tool is closed, 

0 Kudos
nita14
by
Frequent Contributor

Dear Dan,

The name is unique. No warnings at all.

Adam

0 Kudos
DonMorrison1
Frequent Contributor

I've run into the same problem - very simple scenario and there seems to be nothing I can do in my python script to delete the aprx file that I've finished with.  Restarting the python process gets rid of the file but that isn't really an option in my workflow.

0 Kudos
DallasShearer225
New Contributor

I have a script that copies an aprx file to a temporary directory. The script does it's thing but needs to remove the temporary directory when it's done working. I couldn't remove the temp directory b/c of the aprx lock.

I was able to get around it by using the built-in python module atexit. atexit allows you to register a function to run at the end of a script... this may not help you if you're running code from an interactive window. However, for a standalone script this worked for me.  https://docs.python.org/3.7/library/atexit.html

def goodbye(name, adjective):
    print('Goodbye %s, it was %s to meet you.' % (name, adjective))

import atexit

atexit.register(goodbye, 'Donny', 'nice')
# or:
atexit.register(goodbye, adjective='nice', name='Donny')

 

0 Kudos
MatthewGeorge
Frequent Contributor

It'd be great if this could be resolved. Running into the same problem in Pro v3.2.1.