Can someone tell me in my code where I'm not properly dismissing schema locks? Currently when I attempt to run the tessellation, I get ERROR 000464: Cannot get exclusive schema lock. Either being edited or in use by another application.
In this case I am not running the application, only the IDE. What am I missing?
Background: I am taking huge point data files that come to me unprojected, automating a UTM zone projection to put it into metric units, and then making a determination of whether the extent is so big (it fluctuates) that it warrants splitting into smaller chunks, which I will do through tessellation. I am not using minimum bounding geometry because Esri has helpfully limited the Envelope functionality to advanced licenses, and all of my users are on standard licenses 
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">get_vector_center</SPAN><SPAN class="punctuation token">(</SPAN>vector<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
sample_mean <SPAN class="operator token">=</SPAN> <SPAN class="string token">"sample_mean"</SPAN>
sample_center <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>MeanCenter_stats<SPAN class="punctuation token">(</SPAN>vector<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"in_memory/{}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>sample_mean<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">return</SPAN> sample_center
tempgdb <SPAN class="operator token">=</SPAN> <SPAN class="string token">"C:/Temp/scratchdb.gdb"</SPAN>
input_sample <SPAN class="operator token">=</SPAN> <SPAN class="string token">"C:/Temp/dots.shp"</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> tempgdb
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
<SPAN class="comment token"># prep data</SPAN>
utm_fc <SPAN class="operator token">=</SPAN> <SPAN class="string token">"C:/Temp/foundation.gdb/utm_zones_with_epsg"</SPAN>
center <SPAN class="operator token">=</SPAN> get_vector_center<SPAN class="punctuation token">(</SPAN>input_sample<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># do a join</SPAN>
utm_zone <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SpatialJoin_analysis<SPAN class="punctuation token">(</SPAN>utm_fc<SPAN class="punctuation token">,</SPAN> center<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"in_memory/zone"</SPAN><SPAN class="punctuation token">,</SPAN> "<SPAN class="comment token">#", "KEEP_COMMON", "#", "CONTAINS")</SPAN>
<SPAN class="comment token"># get the zone</SPAN>
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"in_memory/zone"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'EPSG'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> vcursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> vcursor<SPAN class="punctuation token">:</SPAN>
epsg <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>int<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><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">"Got EPSG code {}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>epsg<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># construct the sr object</SPAN>
sr <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SpatialReference<SPAN class="punctuation token">(</SPAN>epsg<SPAN class="punctuation token">)</SPAN>
sr<SPAN class="punctuation token">.</SPAN>factoryCode <SPAN class="operator token">=</SPAN> epsg
sr<SPAN class="punctuation token">.</SPAN>create<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># project the original content with the right utm zone</SPAN>
output_layer <SPAN class="operator token">=</SPAN> <SPAN class="string token">"output_utm"</SPAN>
fixed_data <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Project_management<SPAN class="punctuation token">(</SPAN>input_sample<SPAN class="punctuation token">,</SPAN> output_layer<SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># now manually create envelope in correct projection since no advanced license</SPAN>
e <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Describe<SPAN class="punctuation token">(</SPAN>output_layer<SPAN class="punctuation token">)</SPAN>
xmin <SPAN class="operator token">=</SPAN> e<SPAN class="punctuation token">.</SPAN>Extent<SPAN class="punctuation token">.</SPAN>XMin
ymin <SPAN class="operator token">=</SPAN> e<SPAN class="punctuation token">.</SPAN>Extent<SPAN class="punctuation token">.</SPAN>YMin
xmax <SPAN class="operator token">=</SPAN> e<SPAN class="punctuation token">.</SPAN>Extent<SPAN class="punctuation token">.</SPAN>XMax
ymax <SPAN class="operator token">=</SPAN> e<SPAN class="punctuation token">.</SPAN>Extent<SPAN class="punctuation token">.</SPAN>YMax
coordinates <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">(</SPAN>xmin<SPAN class="punctuation token">,</SPAN> ymin<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">(</SPAN>xmin<SPAN class="punctuation token">,</SPAN> ymax<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">(</SPAN>xmax<SPAN class="punctuation token">,</SPAN> ymax<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">(</SPAN>xmax<SPAN class="punctuation token">,</SPAN> ymin<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN>
polygon <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>CreateFeatureclass_management<SPAN class="punctuation token">(</SPAN>tempgdb<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"poly_from_extent"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"POLYGON"</SPAN><SPAN class="punctuation token">,</SPAN> spatial_reference<SPAN class="operator token">=</SPAN>sr<SPAN class="punctuation token">)</SPAN>
feature_class <SPAN class="operator token">=</SPAN> polygon<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># write the geometry from extent to create envelope</SPAN>
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>InsertCursor<SPAN class="punctuation token">(</SPAN>feature_class<SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'SHAPE@'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
cursor<SPAN class="punctuation token">.</SPAN>insertRow<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>coordinates<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
o <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Describe<SPAN class="punctuation token">(</SPAN>feature_class<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># now check for >100km2 area to see if we should tesselate for faster processing</SPAN>
t_out <SPAN class="operator token">=</SPAN> <SPAN class="string token">"parent_tgrid"</SPAN>
oe <SPAN class="operator token">=</SPAN> o<SPAN class="punctuation token">.</SPAN>Extent
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>feature_class<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'SHAPE@AREA'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> acursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> acursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">></SPAN> <SPAN class="number token">100000000</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"{} greater than 10K km2, splitting..."</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
tgrid <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GenerateTessellation_management<SPAN class="punctuation token">(</SPAN>t_out<SPAN class="punctuation token">,</SPAN> oe<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"SQUARE"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">100000000</SPAN><SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Splitting complete"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"point extent smaller than 10K km2, not splitting."</SPAN><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></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><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>