<?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: Multiple Python scrips on features classes in same file geodatabase in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/multiple-python-scrips-on-features-classes-in-same/m-p/569182#M44611</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;They are DOS BAT file commands. They are in the windows help, or were at XP. Strange, does MSoft expect us all to stop using batch files and scheduler??&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://technet.microsoft.com/en-us/library/bb490890.aspx"&gt;http://technet.microsoft.com/en-us/library/bb490890.aspx&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The idea is to cascade back status of each tool to the command script and log all messages to a file so you can see what happened. But now I have found that a lock is always going to happen if you try to update a filegeodatabase with two scripts simultaneously.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have now been reminded why it is not working while looking at the Esri Resources blog. A filegeodatabase is a single user database, and multiple scripts are effectively multiple users, unlike an Enterprise database (Oracle, SQL Server etc) where locks are per featureclass.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://blogs.esri.com/esri/arcgis/category/subject-analysis-and-geoprocessing/page/7/"&gt;http://blogs.esri.com/esri/arcgis/category/subject-analysis-and-geoprocessing/page/7/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]&lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;Here are some important considerations before deciding to use multiprocessing:&lt;BR /&gt;&lt;BR /&gt;The scenario demonstrated in the first example, will not work with feature classes in a file geodatabase because each update must acquire a schema lock on the workspace. A schema lock effectively prevents any other process from simultaneously updating the FGDB. This example will work with shapefiles and ArcSDE geodatabase data.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[/INDENT]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 16 Apr 2013 02:02:06 GMT</pubDate>
    <dc:creator>KimOllivier</dc:creator>
    <dc:date>2013-04-16T02:02:06Z</dc:date>
    <item>
      <title>Multiple Python scrips on features classes in same file geodatabase</title>
      <link>https://community.esri.com/t5/python-questions/multiple-python-scrips-on-features-classes-in-same/m-p/569175#M44604</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have about 5 Python scripts running through Windows Task Scheduler (2008 R2) - they run at varying intervals but will occasionally kick off at the same time (for instance if one is on a 10 min internal, the other 30, and the other 60).&amp;nbsp; They operate on separate feature classes in the same file geodatabase, performing a combination of projections and appends.&amp;nbsp; I regularly but not predictably (or reproducibly) get errors relating to an inability to access a certain feature class (even though it exists).&amp;nbsp; Sometimes there is a lock, sometimes the script says it just can't find it (even though it is most certainly there and no other script is operating on the feature class).&amp;nbsp; Anyway, is there any known issues with multiple python scripts running at once on different feature classes in the same geodatabase.&amp;nbsp; I can't for the life of me reproduce or figure out why these errors are occurring (granted they only occur about 7% of the time, but still, on 10 minute intervals this ends of being a lot of errors).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Apr 2013 14:02:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/multiple-python-scrips-on-features-classes-in-same/m-p/569175#M44604</guid>
      <dc:creator>Jay_Gregory</dc:creator>
      <dc:date>2013-04-08T14:02:21Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Python scrips on features classes in same file geodatabase</title>
      <link>https://community.esri.com/t5/python-questions/multiple-python-scrips-on-features-classes-in-same/m-p/569176#M44605</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;When you run into this again, examine the FGDB folder and pay attention to the .lock files.&amp;nbsp; They will indicate what workstation/server and process(es) has currently locked it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's more info. on FGDB locking:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#/File_geodatabases_and_locking/018s00000006000000/"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#/File_geodatabases_and_locking/018s00000006000000/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If your workflow processes permit, perhaps you can move the feature classes from one FGDB into multiple FGDBs to accommodate multiple processes to access it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sendhil&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Apr 2013 21:28:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/multiple-python-scrips-on-features-classes-in-same/m-p/569176#M44605</guid>
      <dc:creator>SendhilKolandaivel</dc:creator>
      <dc:date>2013-04-08T21:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Python scrips on features classes in same file geodatabase</title>
      <link>https://community.esri.com/t5/python-questions/multiple-python-scrips-on-features-classes-in-same/m-p/569177#M44606</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Can you just run these python scripts in series, so there is never any parallel processing going on within 1 file geodatabase?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would suggest using a bat file to call each python script, so a python script will not get executed until the previous python script has completed its processing.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Apr 2013 13:06:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/multiple-python-scrips-on-features-classes-in-same/m-p/569177#M44606</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2013-04-09T13:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Python scrips on features classes in same file geodatabase</title>
      <link>https://community.esri.com/t5/python-questions/multiple-python-scrips-on-features-classes-in-same/m-p/569178#M44607</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks everyone, I will try the .bat file idea and let you know how it goes.&amp;nbsp; I am still curious in general if running python scripts (in parallel) that operate on &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;different&lt;/SPAN&gt;&lt;SPAN&gt; feature classes in the &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;same&lt;/SPAN&gt;&lt;SPAN&gt; file geodatabase could cause some of these phantom errors.&amp;nbsp; I'm aware that operating on the &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;same&lt;/SPAN&gt;&lt;SPAN&gt; feature class with two processes wouldn't work because of the lock files, but I just thought different feature classes would be ok, since I assumed the lock file applied to the feature class and not the file geodatabase.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any thoughts here?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks, Jay&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Apr 2013 19:55:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/multiple-python-scrips-on-features-classes-in-same/m-p/569178#M44607</guid>
      <dc:creator>Jay_Gregory</dc:creator>
      <dc:date>2013-04-11T19:55:13Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Python scrips on features classes in same file geodatabase</title>
      <link>https://community.esri.com/t5/python-questions/multiple-python-scrips-on-features-classes-in-same/m-p/569179#M44608</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Jay:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In theory I agree with you that locks on different feature classes should not impact other feature classes.&amp;nbsp; Unfortunately I'm not sure whether this works in practice as I do not have any python scripts running in parallel on the same file geodatabase for my Enterprise based scheduled tasks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Apr 2013 16:47:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/multiple-python-scrips-on-features-classes-in-same/m-p/569179#M44608</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2013-04-12T16:47:34Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Python scrips on features classes in same file geodatabase</title>
      <link>https://community.esri.com/t5/python-questions/multiple-python-scrips-on-features-classes-in-same/m-p/569180#M44609</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Maybe your scripts are not as independent as you think. If you are changing a schema of a featureset, then the filegeodatabase will get a lock, not just the featureclass. Locks happen all the time in ArcCatalog if you have it open while running a script from Pythonwin. It is often hard to get rid of the lock without exiting python completely, or ArcCatalog due to arcpy holding on to locks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have found a tool (ExportToKML) that does not release the XML file. Not quite a featureclass, but same principle, so I expect bugs like this in other tools.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can test for schema locks in arcpy. Perhaps put in a test and wait a few minutes in a loop? Also try to ensure that locks are released. You should be able to track down the lock and then it will be easier to recode to avoid it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;At 10.1 use the new capability&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
with arcpy.da.SearchCursor() as cur:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cur:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # do something
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Make sure that you try to release all potential locks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;One way is to wrap tools in a python function, this does a garbage collection on exit.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;try using arcpy.RefreshCatalog(gdb)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you do use BAT files, add in the logging module to log results and return a value so that the batch file can stop on a failure.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;on exit set the return value to 0 or an error message&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the batch file log any messages using:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
set log_file=logPath
python myscript.py &amp;gt;&amp;gt; %log_file% 2&amp;gt;&amp;amp;1
if %errorlevel% neq 0 exit /b %errorlevel%
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cursors and files are only closed when Python does a garbage collection. The "with" construct is better at closing files immediately. It is the closest we have to a file_handle.close() for geoprocessing tools.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:30:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/multiple-python-scrips-on-features-classes-in-same/m-p/569180#M44609</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2021-12-12T00:30:43Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Python scrips on features classes in same file geodatabase</title>
      <link>https://community.esri.com/t5/python-questions/multiple-python-scrips-on-features-classes-in-same/m-p/569181#M44610</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Kim:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You posted the following code to help find locks and errors:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;set log_file=logPath&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;python myscript.py &amp;gt;&amp;gt; %log_file% 2&amp;gt;&amp;amp;1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if %errorlevel% neq 0 exit /b %errorlevel%&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you know the location of good documentation to explain the syntax that you are using (e.g. %log_file% - use of % and errorlevel and finally /b)?&amp;nbsp; I would like to use the code, but I do not completely understand the syntax so additional documentation would be great.&amp;nbsp; Thank you.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Apr 2013 11:32:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/multiple-python-scrips-on-features-classes-in-same/m-p/569181#M44610</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2013-04-15T11:32:57Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Python scrips on features classes in same file geodatabase</title>
      <link>https://community.esri.com/t5/python-questions/multiple-python-scrips-on-features-classes-in-same/m-p/569182#M44611</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;They are DOS BAT file commands. They are in the windows help, or were at XP. Strange, does MSoft expect us all to stop using batch files and scheduler??&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://technet.microsoft.com/en-us/library/bb490890.aspx"&gt;http://technet.microsoft.com/en-us/library/bb490890.aspx&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The idea is to cascade back status of each tool to the command script and log all messages to a file so you can see what happened. But now I have found that a lock is always going to happen if you try to update a filegeodatabase with two scripts simultaneously.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have now been reminded why it is not working while looking at the Esri Resources blog. A filegeodatabase is a single user database, and multiple scripts are effectively multiple users, unlike an Enterprise database (Oracle, SQL Server etc) where locks are per featureclass.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://blogs.esri.com/esri/arcgis/category/subject-analysis-and-geoprocessing/page/7/"&gt;http://blogs.esri.com/esri/arcgis/category/subject-analysis-and-geoprocessing/page/7/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]&lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;Here are some important considerations before deciding to use multiprocessing:&lt;BR /&gt;&lt;BR /&gt;The scenario demonstrated in the first example, will not work with feature classes in a file geodatabase because each update must acquire a schema lock on the workspace. A schema lock effectively prevents any other process from simultaneously updating the FGDB. This example will work with shapefiles and ArcSDE geodatabase data.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[/INDENT]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Apr 2013 02:02:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/multiple-python-scrips-on-features-classes-in-same/m-p/569182#M44611</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2013-04-16T02:02:06Z</dc:date>
    </item>
  </channel>
</rss>

