<?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 stop a command or prompt in Python? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-stop-a-command-or-prompt-in-python/m-p/584516#M45857</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not sure what you mean exactly...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And you are hitting the enter button after typing 'import sys', right?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Are you entering these commands at the prompt in:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-python.exe (the DOS-looking window)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-pythonwin.exe (the freebee python IDE)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-the python window in ArcMap&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-something else?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 31 Mar 2011 17:56:21 GMT</pubDate>
    <dc:creator>ChrisSnyder</dc:creator>
    <dc:date>2011-03-31T17:56:21Z</dc:date>
    <item>
      <title>How to stop a command or prompt in Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-stop-a-command-or-prompt-in-python/m-p/584513#M45854</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm using ArcGIS 10 and I'm practicing a few scripts with Python.&amp;nbsp; What command should I use, if I want to exit a commnad, or a function?&amp;nbsp; I'm always stuck with 3 dots (secondary prompt).&amp;nbsp; How do I stop it?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've tried:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;sys.exit()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sys.exit(0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;quit()&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Mar 2011 16:25:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-stop-a-command-or-prompt-in-python/m-p/584513#M45854</guid>
      <dc:creator>DaveCouture</dc:creator>
      <dc:date>2011-03-31T16:25:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to stop a command or prompt in Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-stop-a-command-or-prompt-in-python/m-p/584514#M45855</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I usually use sys.exit() to stop a script from running if some error condition is met. So for example, if a user put in a wrong input variable...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import sys
var =gp.GetParameterAsText(0)
if var not in ("cat","dog","mouse"):
&amp;nbsp;&amp;nbsp; print "ERROR: You entered the wrong animal! Exiting script..."; sys.exit()
else:
&amp;nbsp;&amp;nbsp; print var + " is a valid entry. Good job!"&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;You might be intersted&amp;nbsp; in the &lt;/SPAN&gt;&lt;STRONG&gt;pass&lt;/STRONG&gt;&lt;SPAN&gt; or &lt;/SPAN&gt;&lt;STRONG&gt;break&lt;/STRONG&gt;&lt;SPAN&gt; statements too...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;pass is used to basically 'do nothing', so something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;if animal == "dog":
&amp;nbsp;&amp;nbsp; pass #aka&amp;nbsp; don't do anything
else:
&amp;nbsp;&amp;nbsp; print "not a dog"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;break is used to break out of a while or for loop, so something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for x in (1,2,3,4,5):&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; if x &amp;gt; 4:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break #aka stop looping
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print x&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:08:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-stop-a-command-or-prompt-in-python/m-p/584514#M45855</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-12T01:08:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to stop a command or prompt in Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-stop-a-command-or-prompt-in-python/m-p/584515#M45856</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the reply and the useful info.&amp;nbsp; However, it's not really what I need.&amp;nbsp; I'm trying to stop everthing and go back to the &lt;/SPAN&gt;&lt;STRONG&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/STRONG&gt;&lt;SPAN&gt;.&amp;nbsp; But I can't, I'm always stuck with the three dots (...). &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example, if I type the following command (&lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;import sys&lt;/SPAN&gt;&lt;SPAN&gt;) and I decide to change my mind and exit out of that command, how would I do it?&amp;nbsp; The &lt;/SPAN&gt;&lt;STRONG&gt;sys.exit() &lt;/STRONG&gt;&lt;SPAN&gt;doesn't work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's what I get:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; import sys&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;... sys.exit()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm always stuck with the 3 dots...why?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Mar 2011 17:02:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-stop-a-command-or-prompt-in-python/m-p/584515#M45856</guid>
      <dc:creator>DaveCouture</dc:creator>
      <dc:date>2011-03-31T17:02:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to stop a command or prompt in Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-stop-a-command-or-prompt-in-python/m-p/584516#M45857</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not sure what you mean exactly...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And you are hitting the enter button after typing 'import sys', right?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Are you entering these commands at the prompt in:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-python.exe (the DOS-looking window)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-pythonwin.exe (the freebee python IDE)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-the python window in ArcMap&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-something else?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Mar 2011 17:56:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-stop-a-command-or-prompt-in-python/m-p/584516#M45857</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2011-03-31T17:56:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to stop a command or prompt in Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-stop-a-command-or-prompt-in-python/m-p/584517#M45858</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm doing it in Python in ArcMap and yes, I do hit Enter at the end of the line.&amp;nbsp; I have experience with VBA and C++, but not with Python.&amp;nbsp; The compiler is really different; it's like scripting live, instead of hitting a RUN button, when you are done scripting....it's more similar to DOS, then anything else.&amp;nbsp; It takes some getting used to!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm just looking for the magic command, to get out of any command that I'm in.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Mar 2011 18:12:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-stop-a-command-or-prompt-in-python/m-p/584517#M45858</guid>
      <dc:creator>DaveCouture</dc:creator>
      <dc:date>2011-03-31T18:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to stop a command or prompt in Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-stop-a-command-or-prompt-in-python/m-p/584518#M45859</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The magic command you're probably looking for is Ctrl-C (Ctrl-Break on some machines), but disappointingly, it does not work at the ArcGIS Python prompt, and even in a standalone console window, if the arcgisscripting (and presumably arcpy) module is loaded then the expected Ctrl-C behavior (throwing a KeyboardInterrupt exception) is broken. I detailed this problem and a workaround &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/13674-KeyboardInterrupt-doesn-t-work-when-arcgisscripting-module-is-loaded"&gt;here&lt;/A&gt;&lt;SPAN&gt;, but again this would most likely not work within the ArcGIS Python prompt presumably because the keyboard accelerators used by the main application are probably lower level/higher priority so they don't reach the Python interpreter.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What specific commands are locking you up? An import statement as in your example should not cause multi-line entry nor long execution times. If statements, loops, try/except/finally constructs and function definitions can though, and the termination/exit command for those are various, such as pass, break, or return. When entering a multi-line construct if you just hit enter or escape does it not return you to the main command prompt?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For anything more significant than poking around arcpy or calling single GP tools you should probably be writing scripts in a real IDE instead of using the ArcGIS Python prompt anyways.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Mar 2011 19:27:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-stop-a-command-or-prompt-in-python/m-p/584518#M45859</guid>
      <dc:creator>LoganPugh</dc:creator>
      <dc:date>2011-03-31T19:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to stop a command or prompt in Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-stop-a-command-or-prompt-in-python/m-p/584519#M45860</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for all the info, I'll try the IDE.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Mar 2011 19:37:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-stop-a-command-or-prompt-in-python/m-p/584519#M45860</guid>
      <dc:creator>DaveCouture</dc:creator>
      <dc:date>2011-03-31T19:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to stop a command or prompt in Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-stop-a-command-or-prompt-in-python/m-p/584520#M45861</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The ArcMap Python window "claims" that Esc will do it, but... not so sure.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Mar 2011 20:22:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-stop-a-command-or-prompt-in-python/m-p/584520#M45861</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2011-03-31T20:22:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to stop a command or prompt in Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-stop-a-command-or-prompt-in-python/m-p/584521#M45862</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I can vouch for the effectiveness of the following process:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Click on the 'Results' window,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Click on the 'Current Session' text,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;3. Right-click on the uppermost process (i.e. the one that is currently running) and select 'Cancel'.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This should interupt all processes, unless there is a statement that catches errors, in which case you may have to repeat the process a few times.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Jun 2013 14:03:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-stop-a-command-or-prompt-in-python/m-p/584521#M45862</guid>
      <dc:creator>SamRoberson</dc:creator>
      <dc:date>2013-06-07T14:03:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to stop a command or prompt in Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-stop-a-command-or-prompt-in-python/m-p/584522#M45863</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It almost sounds to me like you have a corrupt python install.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In python.exe, IDE, or the python window in ArcMap, I can not repeat.&amp;nbsp; The only time I can get the ... is if I do a multiline entry ( IE, if this == "that":) or nested code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;an import statement should never be "seen" as a multiline entry or nested code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Curious what happens if you type this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt;print "testing"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you get:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt;print "testing"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;testing&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;or do you get:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt;print "testing"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you get the latter, I would try a remove/re-install of your python.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Jun 2013 00:31:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-stop-a-command-or-prompt-in-python/m-p/584522#M45863</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2013-06-11T00:31:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to stop a command or prompt in Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-stop-a-command-or-prompt-in-python/m-p/584523#M45864</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This did not work for me. I had a loop running a selection and writing values to a text file and cancel would only effectively cancel the current selection. I tried cancel about 10 times before calling it quits. One thing that will always work is "End Process" in the task manager but that is probably not recommended.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Sep 2015 19:55:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-stop-a-command-or-prompt-in-python/m-p/584523#M45864</guid>
      <dc:creator>JohnChurchill</dc:creator>
      <dc:date>2015-09-08T19:55:49Z</dc:date>
    </item>
  </channel>
</rss>

