Hello everyone,
I feel like I've been plagued with unusual Python 3.x (arcpy) issues ever since I upgraded to 2.6.x
The latest issues I'm facing include stale SDE connections and state locks not properly releasing upon completion when I am disabling/enabling Editor Tracking (arcpy.EnableEditorTracking_management and arcpy.DisableEditorTracking_management).
My workflow includes disabling editor tracking, calculating some values with an update cursor, then re-enabling editor tracking on an SDE database.
After discovering some locking issues not going away, I've isolated the issue specifically to the enabling/disabling of editor tracking. I've created a testing environment (and script) for studying these tools specifically which will be provided below.
Usually, arcpy.ClearWorkspaceCache_management does the trick and cleans up the script's locks, but that isn't working with the above tools for whatever reason in Pro 2.6 update of Python. To provide more clarity, I run many workflow tools in sequence so my goal is to clean up all locks affiliated with each tool before beginning the next.
I have confirmed that the state locks are properly releasing in the Python 2.7 flavor of arcpy, and I never had issues with Pro 2.2-2.5 with these issues either.
Here is my script that I've been testing with:
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">from</SPAN> Static_Values <SPAN class="keyword token">import</SPAN> Class_Static_Values <SPAN class="keyword token">as</SPAN> stat_val
<SPAN class="keyword token">import</SPAN> time
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> stat_val<SPAN class="punctuation token">.</SPAN>sdeConnection_RegionalGIS_DefaultVersion
fc_list <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFeatureClasses<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> fc <SPAN class="keyword token">in</SPAN> fc_list<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="string token">"EMS"</SPAN> <SPAN class="keyword token">in</SPAN> fc<SPAN class="punctuation token">:</SPAN>
<SPAN class="comment token">#arcpy.DisableEditorTracking_management(fc,</SPAN>
<SPAN class="comment token"># "DISABLE_CREATOR",</SPAN>
<SPAN class="comment token"># "DISABLE_CREATION_DATE",</SPAN>
<SPAN class="comment token"># "DISABLE_LAST_EDITOR",</SPAN>
<SPAN class="comment token"># "DISABLE_LAST_EDIT_DATE")</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>EnableEditorTracking_management<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"CreateID"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"DateCreate"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"UpdateID"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"DateUpdate"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"NO_ADD_FIELDS"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"UTC"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>GetMessages<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"attempting to remove locks..."</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>ClearWorkspaceCache_management<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"attempt complete..."</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># The following loop allows me to review/refresh the Geodatabase Administration window for 10 seconds to verify if any locks still exist from the above line of code.</SPAN>
counter <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN>
<SPAN class="keyword token">while</SPAN> counter <SPAN class="operator token"><</SPAN> <SPAN class="number token">10</SPAN><SPAN class="punctuation token">:</SPAN>
time<SPAN class="punctuation token">.</SPAN>sleep<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN>
counter <SPAN class="operator token">=</SPAN> counter <SPAN class="operator token">+</SPAN> <SPAN class="number token">1</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Has anyone else encountered this, or can you think of other options to try in order to clean up the locks?
Once the above, isolated script gets to Line 33, two stale SDE connections and two persistent state locks remain and do not go away until the script completes its full execution after Line 41.
The two stale connections are highlighted here (ignore the grayed out one, as that is my current view within Catalog for studying purposes):

The two persistent state locks are highlighted here (ignore the grayed out one, as that is my current view within Catalog for studying purposes):

Interestingly enough, I can get one of these state locks to disappear if I include the line arcpy.env.workspace = None just before the arcpy.ClearWorkspaceCache_management() line, but I don't recall ever needing to do that. I also can't figure out what else is leaving the other state lock. I've tried resetting the environment, clearing the cache, garbage collection, as well as deleting the fc_list variable with no luck.
Any help or insight would be most appreciated!