<?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: python add-in hanging due to while loop in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-add-in-hanging-due-to-while-loop/m-p/663874#M51575</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jelmer,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Can you please elaborate on this issue with the snippet that you have coded.&lt;/P&gt;&lt;P&gt;&amp;nbsp; From the information provided, i can suggest you to use event listeners to achieve the trigger ,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp; #function that keeps checking if the second button is pressed.
def IsButtonPressed():
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (&amp;lt;your condition for the event&amp;gt;):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return True
&amp;nbsp;&amp;nbsp;&amp;nbsp; else :
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return False


&amp;nbsp; #function that keeps looping after the first button is pressed.
def Loop():
&amp;nbsp;&amp;nbsp; while (IsButtonPressed()):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;do some action&amp;gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;If you can specify which GUI framework you are using , i can help with the events trigger part.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Jai&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 04:04:00 GMT</pubDate>
    <dc:creator>JaiSiva1</dc:creator>
    <dc:date>2021-12-12T04:04:00Z</dc:date>
    <item>
      <title>python add-in hanging due to while loop</title>
      <link>https://community.esri.com/t5/python-questions/python-add-in-hanging-due-to-while-loop/m-p/663873#M51574</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm building a python add-in for ArcGIS desktop with a button which runs a while loop. Another button should close the while loop. In the while loop there is a continuous process going on which is important for the functionality of the add-in. But unfortunately the while loop causes the add-in, and therefore ArcGIS desktop, to hang.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tried time.sleep(.1) in the while loop. And I have tried the threading library. But nothing seems to work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was hoping someone maybe had a suggestion? Thanks in advance!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 May 2015 09:59:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-add-in-hanging-due-to-while-loop/m-p/663873#M51574</guid>
      <dc:creator>JelmerOosthoek</dc:creator>
      <dc:date>2015-05-05T09:59:01Z</dc:date>
    </item>
    <item>
      <title>Re: python add-in hanging due to while loop</title>
      <link>https://community.esri.com/t5/python-questions/python-add-in-hanging-due-to-while-loop/m-p/663874#M51575</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jelmer,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Can you please elaborate on this issue with the snippet that you have coded.&lt;/P&gt;&lt;P&gt;&amp;nbsp; From the information provided, i can suggest you to use event listeners to achieve the trigger ,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp; #function that keeps checking if the second button is pressed.
def IsButtonPressed():
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (&amp;lt;your condition for the event&amp;gt;):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return True
&amp;nbsp;&amp;nbsp;&amp;nbsp; else :
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return False


&amp;nbsp; #function that keeps looping after the first button is pressed.
def Loop():
&amp;nbsp;&amp;nbsp; while (IsButtonPressed()):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;do some action&amp;gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;If you can specify which GUI framework you are using , i can help with the events trigger part.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Jai&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:04:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-add-in-hanging-due-to-while-loop/m-p/663874#M51575</guid>
      <dc:creator>JaiSiva1</dc:creator>
      <dc:date>2021-12-12T04:04:00Z</dc:date>
    </item>
    <item>
      <title>Re: python add-in hanging due to while loop</title>
      <link>https://community.esri.com/t5/python-questions/python-add-in-hanging-due-to-while-loop/m-p/663875#M51576</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jai, thanks for your reply.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm currently not using any other GUI framework than ArcGIS itself, using the python add-in wizard: &lt;A href="https://www.arcgis.com/home/item.html?id=5f3aefe77f6b4f61ad3e4c62f30bff3b" title="https://www.arcgis.com/home/item.html?id=5f3aefe77f6b4f61ad3e4c62f30bff3b" rel="nofollow noopener noreferrer" target="_blank"&gt;https://www.arcgis.com/home/item.html?id=5f3aefe77f6b4f61ad3e4c62f30bff3b&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And by using a while loop in the code the tool and ArcGIS hangs. Here is a simple snippet example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import pythonaddins


class ButtonClass1(object):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for tryaddin_addin.button (Button)"""
&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.enabled = True
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.checked = False
&amp;nbsp;&amp;nbsp;&amp;nbsp; def onClick(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # the while loop
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; global switch
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while switch == 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; global switch


class ButtonClass2(object):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for tryaddin_addin.button_2 (Button)"""
&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.enabled = True
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.checked = False
&amp;nbsp;&amp;nbsp;&amp;nbsp; def onClick(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # turn off the while loop
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; global switch
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; switch = 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
switch = 0&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:04:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-add-in-hanging-due-to-while-loop/m-p/663875#M51576</guid>
      <dc:creator>JelmerOosthoek</dc:creator>
      <dc:date>2021-12-12T04:04:02Z</dc:date>
    </item>
    <item>
      <title>Re: python add-in hanging due to while loop</title>
      <link>https://community.esri.com/t5/python-questions/python-add-in-hanging-due-to-while-loop/m-p/663876#M51577</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jelmer ,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; I think you got to change the logic that you have written in your program.&lt;/P&gt;&lt;P&gt; I have a similar kind of case which uses Tkinter package , using which you can modify your code.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;A href="http://stackoverflow.com/questions/27050492/how-do-you-create-a-tkinter-gui-stop-button-to-break-an-infinite-loop" title="http://stackoverflow.com/questions/27050492/how-do-you-create-a-tkinter-gui-stop-button-to-break-an-infinite-loop"&gt;python - How do you create a Tkinter GUI stop button to break an infinite loop? - Stack Overflow&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; Hope this is useful. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 May 2015 13:23:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-add-in-hanging-due-to-while-loop/m-p/663876#M51577</guid>
      <dc:creator>JaiSiva1</dc:creator>
      <dc:date>2015-05-06T13:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: python add-in hanging due to while loop</title>
      <link>https://community.esri.com/t5/python-questions/python-add-in-hanging-due-to-while-loop/m-p/663877#M51578</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jai,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That did the trick! Thanks very much, it works like a charm, and doesn't even need threading.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;All the best, Jelmer&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 May 2015 14:38:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-add-in-hanging-due-to-while-loop/m-p/663877#M51578</guid>
      <dc:creator>JelmerOosthoek</dc:creator>
      <dc:date>2015-05-06T14:38:09Z</dc:date>
    </item>
  </channel>
</rss>

