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