<?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: Bug with arcpy in a thread in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/bug-with-arcpy-in-a-thread/m-p/708974#M54958</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN style="font-family:Courier New;"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN&gt; does not work threaded. It is not a bug, it is a longstanding architecture issue. Please investigate using multiprocessing or some other non-threaded concurrency model for doing parallel processing.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 30 Jul 2012 08:10:30 GMT</pubDate>
    <dc:creator>JasonScheirer</dc:creator>
    <dc:date>2012-07-30T08:10:30Z</dc:date>
    <item>
      <title>Bug with arcpy in a thread</title>
      <link>https://community.esri.com/t5/python-questions/bug-with-arcpy-in-a-thread/m-p/708973#M54957</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am trying to use arcpy within a thread and am getting unexpected results from arcpy.Exists:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-family:Courier New;"&gt;import threading&lt;BR /&gt;import arcpy&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;class ThreadTest(threading.Thread):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self,):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; threading.Thread.__init__(self)&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def run(self):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.Exists(r'E:\nothing.gdb'):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(r'E:\nothing.gdb')&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;if __name__=='__main__':&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; tt = ThreadTest()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; tt.start()&lt;BR /&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This results in arcpy.Exists returning True when the .gdb does not exist (or anything even close) and then an error when trying to delete it as it does not in fact exist.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I move the import arcpy line from the top to the run method, the problem disappears, however this is not a solution as it seems to only work for the thread that arcpy is initially imported in. What if I need a second thread?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I put the if exists test under the if __name__==... line (and therefore in the thread where arcpy is initially imported) all works fine.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For some background, I'm trying to use this with a GUI so I only need one thread, but I need the processing to happen in that thread whilst the main thread continues to serve GUI events.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Am I doing something wrong, or is this a bug?&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;Adam&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jul 2012 05:11:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/bug-with-arcpy-in-a-thread/m-p/708973#M54957</guid>
      <dc:creator>AdamKerz</dc:creator>
      <dc:date>2012-07-30T05:11:48Z</dc:date>
    </item>
    <item>
      <title>Re: Bug with arcpy in a thread</title>
      <link>https://community.esri.com/t5/python-questions/bug-with-arcpy-in-a-thread/m-p/708974#M54958</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN style="font-family:Courier New;"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN&gt; does not work threaded. It is not a bug, it is a longstanding architecture issue. Please investigate using multiprocessing or some other non-threaded concurrency model for doing parallel processing.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jul 2012 08:10:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/bug-with-arcpy-in-a-thread/m-p/708974#M54958</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2012-07-30T08:10:30Z</dc:date>
    </item>
  </channel>
</rss>

