<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to remove Lock? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-remove-lock/m-p/440070#M34499</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Zuoqi Chen,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Having a dataset locked can be a difficult thing to solve. IMHO I thing the locking mechanism in ArcGIS has been implemented to drastic, causing more problems than it avoids...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I assume you are writing your raster datasets to a file geodatabase. It is possible to test the scema locking before deleting and place it in a "try except" (as shown below), but this doesn't solve anything if you have a lock on your dataset. Always be sure to delete any references to your dataset and delete cursors, rows, etc...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
if arcpy.TestSchemaLock(data):
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete(data)
&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # catch error here
 else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Unable to acquire schema lock"
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;source: &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/TestSchemaLock/018v0000002m000000/" rel="nofollow noopener noreferrer" target="_blank"&gt;http://resources.arcgis.com/en/help/main/10.2/index.html#/TestSchemaLock/018v0000002m000000/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What I have also come across is using the garbage collector. This may sometimes solve the problem. See snippet below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; # at beginning of script
&amp;nbsp;&amp;nbsp;&amp;nbsp; import gc # Garbage Collector
&amp;nbsp;&amp;nbsp;&amp;nbsp; gc.collect()

&amp;nbsp;&amp;nbsp;&amp;nbsp; # at end of script
&amp;nbsp;&amp;nbsp;&amp;nbsp; collected = gc.collect()
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Garbage collector: collected %d objects." % (collected)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # try to delete now...
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;sources: &lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://gis.stackexchange.com/questions/19408/arcgis-10-0-python-searchcursor-file-locking" rel="nofollow noopener noreferrer" target="_blank"&gt;http://gis.stackexchange.com/questions/19408/arcgis-10-0-python-searchcursor-file-locking&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://docs.python.org/2/library/gc.html" rel="nofollow noopener noreferrer" target="_blank"&gt;http://docs.python.org/2/library/gc.html&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://pymotw.com/2/gc/" rel="nofollow noopener noreferrer" target="_blank"&gt;http://pymotw.com/2/gc/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If this doesn't work, you could go back to the gold old Esri grid data format (write raster to folder), which is probably one of the last formats for which the locking mechanism hasn't been implemented. &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt; This did solve some nasty locking problems I had...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 19:41:30 GMT</pubDate>
    <dc:creator>XanderBakker</dc:creator>
    <dc:date>2021-12-11T19:41:30Z</dc:date>
    <item>
      <title>How to remove Lock?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-remove-lock/m-p/440069#M34498</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I creat a loop.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;In the loop, it makes a HillShade Raster (named A) and makes a new Raster (named B) from A.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;But the Raster A can not be delete because the Raster A is Locked. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;How can i solve this?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Aug 2013 05:28:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-remove-lock/m-p/440069#M34498</guid>
      <dc:creator>ZuoqiChen</dc:creator>
      <dc:date>2013-08-30T05:28:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove Lock?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-remove-lock/m-p/440070#M34499</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Zuoqi Chen,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Having a dataset locked can be a difficult thing to solve. IMHO I thing the locking mechanism in ArcGIS has been implemented to drastic, causing more problems than it avoids...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I assume you are writing your raster datasets to a file geodatabase. It is possible to test the scema locking before deleting and place it in a "try except" (as shown below), but this doesn't solve anything if you have a lock on your dataset. Always be sure to delete any references to your dataset and delete cursors, rows, etc...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
if arcpy.TestSchemaLock(data):
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete(data)
&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # catch error here
 else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Unable to acquire schema lock"
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;source: &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/TestSchemaLock/018v0000002m000000/" rel="nofollow noopener noreferrer" target="_blank"&gt;http://resources.arcgis.com/en/help/main/10.2/index.html#/TestSchemaLock/018v0000002m000000/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What I have also come across is using the garbage collector. This may sometimes solve the problem. See snippet below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; # at beginning of script
&amp;nbsp;&amp;nbsp;&amp;nbsp; import gc # Garbage Collector
&amp;nbsp;&amp;nbsp;&amp;nbsp; gc.collect()

&amp;nbsp;&amp;nbsp;&amp;nbsp; # at end of script
&amp;nbsp;&amp;nbsp;&amp;nbsp; collected = gc.collect()
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Garbage collector: collected %d objects." % (collected)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # try to delete now...
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;sources: &lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://gis.stackexchange.com/questions/19408/arcgis-10-0-python-searchcursor-file-locking" rel="nofollow noopener noreferrer" target="_blank"&gt;http://gis.stackexchange.com/questions/19408/arcgis-10-0-python-searchcursor-file-locking&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://docs.python.org/2/library/gc.html" rel="nofollow noopener noreferrer" target="_blank"&gt;http://docs.python.org/2/library/gc.html&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://pymotw.com/2/gc/" rel="nofollow noopener noreferrer" target="_blank"&gt;http://pymotw.com/2/gc/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If this doesn't work, you could go back to the gold old Esri grid data format (write raster to folder), which is probably one of the last formats for which the locking mechanism hasn't been implemented. &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt; This did solve some nasty locking problems I had...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:41:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-remove-lock/m-p/440070#M34499</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-11T19:41:30Z</dc:date>
    </item>
  </channel>
</rss>

