I'm working on a Python script that involves selecting parcels from a feature class and I've run into some odd behavior in my sanity checks. In the code below I loop through the list of specified tax ID numbers and use the MakeTableView trick to get a count of elements matching a specific "where" clause. If I only give it one tax ID, the script finishes in a couple of seconds. If I give it two, it gets stuck on MakeTableView for about 4 minutes, and this seems to increase by about 4 minutes for each additional tax ID. I've tried explicitly deleting the resulting table view as soon as I'm finished with it, but that made no difference.
Ultimately, I changed the script to use a search cursor and the "where" clause to give me the same functionality, but this is just bouncing around the back of my head—why would the subsequent MakeTableView calls perform so much slower than the first?
Edit for clarity: TID is a list of tax ID's obtained by splitting a multi-value GetParameterAsText().
<SPAN class="comment token"># Add all desired parcels to selection</SPAN>
<SPAN class="keyword token">for</SPAN> tid <SPAN class="keyword token">in</SPAN> TID<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> tid <SPAN class="operator token">and</SPAN> tid <SPAN class="operator token">!=</SPAN> "<SPAN class="comment token">#":</SPAN>
<SPAN class="comment token"># Make sure the parcel ID is formatted correctly</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="operator token">not</SPAN> re<SPAN class="punctuation token">.</SPAN>match<SPAN class="punctuation token">(</SPAN>pattern<SPAN class="punctuation token">,</SPAN> tid<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">raise</SPAN> GPException<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Input Parcel IDs must be in the format "</SPAN> <SPAN class="operator token">+</SPAN>
<SPAN class="string token">"YY-YYY-YYYY, where Y is a single digit number."</SPAN> <SPAN class="operator token">+</SPAN>
<SPAN class="string token">" For example, 06-019-0009."</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Make sure parcel ID is a valid parcel</SPAN>
where <SPAN class="operator token">=</SPAN> TID_field <SPAN class="operator token">+</SPAN> <SPAN class="string token">" = '"</SPAN> <SPAN class="operator token">+</SPAN> tid <SPAN class="operator token">+</SPAN> <SPAN class="string token">"'"</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>MakeTableView_management<SPAN class="punctuation token">(</SPAN>parcels<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"in_memory/temp"</SPAN><SPAN class="punctuation token">,</SPAN> where<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetCount_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"in_memory/temp"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token"><</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">raise</SPAN> GPException<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Cannot find parcel ID "</SPAN> <SPAN class="operator token">+</SPAN> tid <SPAN class="operator token">+</SPAN> <SPAN class="string token">" in parcel "</SPAN> <SPAN class="operator token">+</SPAN>
<SPAN class="string token">"list."</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"in_memory/temp"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Finally, add it to the selection if it's passed all the checks</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute_management<SPAN class="punctuation token">(</SPAN>parcels<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"ADD_TO_SELECTION"</SPAN><SPAN class="punctuation token">,</SPAN> where<SPAN class="punctuation token">)</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>