<?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 Python WITH statement does not release da cursor schema locks in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/python-with-statement-does-not-release-da-cursor/m-p/138620#M4702</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;According to this page&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//002z0000001q000000" rel="nofollow noopener noreferrer" target="_blank"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#//002z0000001q000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The Python WITH statement should release all data access cursor locks.&amp;nbsp; It doesn't release schema locks.&amp;nbsp; *sr.LOCK files persist.&amp;nbsp; For example, foo remains locked after the following code is run: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
with arcpy.da.SearchCursor( 'C:/Temp/foo.shp' , [ "*" ] ) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[0]
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My questions are... &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1) Is this by design?&amp;nbsp; It kind of makes sense,&amp;nbsp; since one can go on and use the cursor some more even after the with block is exited.&amp;nbsp; Seems like it would be bad to edit the schema while you've got a cursor pointing to that file.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2) if this is not by design, is someone going to fix it soon?&amp;nbsp; If so, when?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;3) If this is by design, why use the WITH statement in all the examples?&amp;nbsp; Sure, it gets rid of the read/write locks, but it doesn't remove all locks, so it messes up your workflow anyway. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;4) If this is by design, shouldn't the documentation be modified?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the help.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 07:40:56 GMT</pubDate>
    <dc:creator>LT</dc:creator>
    <dc:date>2021-12-11T07:40:56Z</dc:date>
    <item>
      <title>Python WITH statement does not release da cursor schema locks</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-with-statement-does-not-release-da-cursor/m-p/138620#M4702</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;According to this page&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//002z0000001q000000" rel="nofollow noopener noreferrer" target="_blank"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#//002z0000001q000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The Python WITH statement should release all data access cursor locks.&amp;nbsp; It doesn't release schema locks.&amp;nbsp; *sr.LOCK files persist.&amp;nbsp; For example, foo remains locked after the following code is run: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
with arcpy.da.SearchCursor( 'C:/Temp/foo.shp' , [ "*" ] ) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[0]
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My questions are... &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1) Is this by design?&amp;nbsp; It kind of makes sense,&amp;nbsp; since one can go on and use the cursor some more even after the with block is exited.&amp;nbsp; Seems like it would be bad to edit the schema while you've got a cursor pointing to that file.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2) if this is not by design, is someone going to fix it soon?&amp;nbsp; If so, when?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;3) If this is by design, why use the WITH statement in all the examples?&amp;nbsp; Sure, it gets rid of the read/write locks, but it doesn't remove all locks, so it messes up your workflow anyway. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;4) If this is by design, shouldn't the documentation be modified?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the help.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:40:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-with-statement-does-not-release-da-cursor/m-p/138620#M4702</guid>
      <dc:creator>LT</dc:creator>
      <dc:date>2021-12-11T07:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: Python WITH statement does not release da cursor schema locks</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-with-statement-does-not-release-da-cursor/m-p/138621#M4703</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I tested this with a few shapefiles and it releases all of the locks for me. I am at 10.1 Service Pack 1, Windows 7 64 bit. What is your set up? Perhaps the issue is specific to a different configuration. Otherwise, could you try this on a co-worker's machine and have another user log into your machine to see if the issue persists?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Mar 2013 21:00:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-with-statement-does-not-release-da-cursor/m-p/138621#M4703</guid>
      <dc:creator>LucasDanzinger</dc:creator>
      <dc:date>2013-03-04T21:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: Python WITH statement does not release da cursor schema locks</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-with-statement-does-not-release-da-cursor/m-p/138622#M4704</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the reply. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have tested this on several machines.&amp;nbsp; The behavior is the same.&amp;nbsp; The schema lock is not released until the cursor is deleted.&amp;nbsp; You can see it when you look in the directory in Windows Explorer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I should add that I'm running this code in PythonWin in a stand-alone script, not in the Python window within ArcMap.&amp;nbsp; Is that how you tried it too?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Mar 2013 21:16:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-with-statement-does-not-release-da-cursor/m-p/138622#M4704</guid>
      <dc:creator>LT</dc:creator>
      <dc:date>2013-03-04T21:16:54Z</dc:date>
    </item>
    <item>
      <title>Re: Python WITH statement does not release da cursor schema locks</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-with-statement-does-not-release-da-cursor/m-p/138623#M4705</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I should add that I have Windows 7 64-bit , 10.1 with service pack 1.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Mar 2013 21:18:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-with-statement-does-not-release-da-cursor/m-p/138623#M4705</guid>
      <dc:creator>LT</dc:creator>
      <dc:date>2013-03-04T21:18:18Z</dc:date>
    </item>
    <item>
      <title>Re: Python WITH statement does not release da cursor schema locks</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-with-statement-does-not-release-da-cursor/m-p/138624#M4706</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hmmm I'm wondering if I wasn't quite specific enough.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Have you tried running the code and then viewing the shapefile components in Windows Explorer? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The following pic was taking while a cursor was active.&amp;nbsp; After the with block was existed, the rd.lock file disappears. But the sr.lock file remains.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]22361[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your input.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Mar 2013 22:54:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-with-statement-does-not-release-da-cursor/m-p/138624#M4706</guid>
      <dc:creator>LT</dc:creator>
      <dc:date>2013-03-04T22:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: Python WITH statement does not release da cursor schema locks</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-with-statement-does-not-release-da-cursor/m-p/138625#M4707</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, I was viewing the locks through Windows Explorer as well... I am at 10.1 SP1 with Windows 7 64 bit as well. I ran it through PyScipter, so I will test it in PythonWin and let you know.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Mar 2013 20:07:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-with-statement-does-not-release-da-cursor/m-p/138625#M4707</guid>
      <dc:creator>LucasDanzinger</dc:creator>
      <dc:date>2013-03-05T20:07:47Z</dc:date>
    </item>
    <item>
      <title>Re: Python WITH statement does not release da cursor schema locks</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-with-statement-does-not-release-da-cursor/m-p/138626#M4708</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Interesting. So here is what I found. The IDE does not make a difference. When I run it and it gets rid of the locks, I use the following syntax:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

def main():
&amp;nbsp;&amp;nbsp;&amp;nbsp; fc = r"C:\TestData\500ft_Grid.shp"
&amp;nbsp;&amp;nbsp;&amp;nbsp; fields = ["*"]
&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(fc, fields) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(row)

if __name__ == '__main__':
&amp;nbsp;&amp;nbsp;&amp;nbsp; main()
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I take it out of a function and just do the following, the sr lock remains:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fc = r"C:\TestData\500ft_Grid.shp"
fields = ["*"]
with arcpy.da.SearchCursor(fc, fields) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(row)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'll have to get back to you with more information.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Luke&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:40:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-with-statement-does-not-release-da-cursor/m-p/138626#M4708</guid>
      <dc:creator>LucasDanzinger</dc:creator>
      <dc:date>2021-12-11T07:40:58Z</dc:date>
    </item>
    <item>
      <title>Re: Python WITH statement does not release da cursor schema locks</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-with-statement-does-not-release-da-cursor/m-p/138627#M4709</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The reason it worked when I had it in a function is because the variables were automatically deleted once the code in the function completed successfully. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Since I was able to reproduce the issue, I logged the following bug for this: NIM089529: The data access arcpy cursors do not release locks when using with statement.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Luke&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Mar 2013 22:03:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-with-statement-does-not-release-da-cursor/m-p/138627#M4709</guid>
      <dc:creator>LucasDanzinger</dc:creator>
      <dc:date>2013-03-05T22:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: Python WITH statement does not release da cursor schema locks</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-with-statement-does-not-release-da-cursor/m-p/138628#M4710</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you, Luke!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Mar 2013 00:44:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-with-statement-does-not-release-da-cursor/m-p/138628#M4710</guid>
      <dc:creator>LT</dc:creator>
      <dc:date>2013-03-06T00:44:38Z</dc:date>
    </item>
    <item>
      <title>Re: Python WITH statement does not release da cursor schema locks</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-with-statement-does-not-release-da-cursor/m-p/138629#M4711</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Bug BUG-000083762: In each cursor documentation, specify the type of lock being closed and released, as a shared lock is still present in the geodatabase after the 'with' statement executes.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Dec 2014 23:04:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-with-statement-does-not-release-da-cursor/m-p/138629#M4711</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2014-12-04T23:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: Python WITH statement does not release da cursor schema locks</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-with-statement-does-not-release-da-cursor/m-p/138630#M4712</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I did some quick testing &lt;A _jive_internal="true" href="https://community.esri.com/message/452799#452799"&gt;here&lt;/A&gt; and I confirmed what Luke found: running the &lt;SPAN style="font-family: 'courier new', courier;"&gt;with&lt;/SPAN&gt; statement in a function removes the locks while running it alone (outside a function) leaves the locks. &lt;EM&gt;However&lt;/EM&gt;, if you run the &lt;SPAN style="font-family: 'courier new', courier;"&gt;with&lt;/SPAN&gt; statement outside of a function, the locks only remain until you close the IDE (I was using PyScripter). Same thing if you just run the .py file with python.exe, the locks are removed when the script has finished running.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jan 2015 21:31:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-with-statement-does-not-release-da-cursor/m-p/138630#M4712</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2015-01-27T21:31:13Z</dc:date>
    </item>
    <item>
      <title>Re: Python WITH statement does not release da cursor schema locks</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-with-statement-does-not-release-da-cursor/m-p/138631#M4713</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/25477"&gt;Lucas Danzinger&lt;/A&gt;‌ addressed this behavior in one of his earlier replies to this thread, i.e., the locks are removed by the Python interpreter when the cursor objects go out of scope by either having the function end or having the IDE/interpreter closed out.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jan 2015 21:44:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-with-statement-does-not-release-da-cursor/m-p/138631#M4713</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2015-01-27T21:44:56Z</dc:date>
    </item>
  </channel>
</rss>

