<?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: Close event passed to python script when canceling toolbox script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/close-event-passed-to-python-script-when-canceling/m-p/12701#M1025</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; . First, I am unclear as to what type of signal is passed to the script that enables ESRI to terminate it, and second I am not sure how to detect the event and then run a clean up based on this signal.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Back then in 2007 &lt;/SPAN&gt;&lt;A href="http://forums.esri.com/thread.asp?c=93&amp;amp;f=1729&amp;amp;t=235457"&gt;(I think this is the post)&lt;/A&gt;&lt;SPAN&gt; was a while ago. I think the glue is much better now.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm pretty sure what's passed now would be &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v00000119000000"&gt;arcpy.ExecuteError&lt;/A&gt;&lt;SPAN&gt; like any other tool failure. You can trap for that exception class, but you would then want to search the error message strings for error codes from the arcpy.getMessages() array to verify the cancel was what generated the ExecuteError. I'd just try it with your script to find out which particular error code pops up from your cancel, in case it depends on context in your script. For example, if you get error &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00vz00000007085022.htm"&gt;080522&lt;/A&gt;&lt;SPAN&gt; you would scan through the messages for the text " 080522:".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Update:&lt;/STRONG&gt;&lt;SPAN&gt; I tried it this morning and it's true, if a tool isn't running when Cancel is pressed, the script process just dies, with no error message or anything saved in the results. That's not good as it looks like ArcGIS is just zapping the subprocess with a kill. I have no advice, sorry, and hope someone (from Esri) can chime in that knows some of the internals here.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I believe I might be able to use win32api, but I have not figured it out yet. For example:&lt;BR /&gt;win32api.SetConsoleCtrlHandler(func, True)&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I believe this was non-trivial on Windows platforms in the past, but Python 2.6 includes a nifty Popen.kill() method on the &lt;/SPAN&gt;&lt;A href="http://docs.python.org/library/subprocess.html"&gt;subprocess&lt;/A&gt;&lt;SPAN&gt; module.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 12 Apr 2012 04:29:34 GMT</pubDate>
    <dc:creator>curtvprice</dc:creator>
    <dc:date>2012-04-12T04:29:34Z</dc:date>
    <item>
      <title>Close event passed to python script when canceling toolbox script</title>
      <link>https://community.esri.com/t5/python-questions/close-event-passed-to-python-script-when-canceling/m-p/12700#M1024</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have written a program that spawns jobs and I would like to kill these jobs when the native python script (invoked from toolbox) is canceled from the results tab of ArcMap or ArcCatalog. First, I am unclear as to what type of signal is passed to the script that enables ESRI to terminate it, and second I am not sure how to detect the event and then run a clean up based on this signal. Has anyone tried this before. There was a post on ESRI a couple years ago but no one figured it out and therefore there was no posted resolution.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I believe I might be able to use win32api, but I have not figured it out yet. For example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;win32api.SetConsoleCtrlHandler(func, True)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Apr 2012 00:29:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/close-event-passed-to-python-script-when-canceling/m-p/12700#M1024</guid>
      <dc:creator>MichaelO_Donnell1</dc:creator>
      <dc:date>2012-04-12T00:29:13Z</dc:date>
    </item>
    <item>
      <title>Re: Close event passed to python script when canceling toolbox script</title>
      <link>https://community.esri.com/t5/python-questions/close-event-passed-to-python-script-when-canceling/m-p/12701#M1025</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; . First, I am unclear as to what type of signal is passed to the script that enables ESRI to terminate it, and second I am not sure how to detect the event and then run a clean up based on this signal.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Back then in 2007 &lt;/SPAN&gt;&lt;A href="http://forums.esri.com/thread.asp?c=93&amp;amp;f=1729&amp;amp;t=235457"&gt;(I think this is the post)&lt;/A&gt;&lt;SPAN&gt; was a while ago. I think the glue is much better now.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm pretty sure what's passed now would be &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v00000119000000"&gt;arcpy.ExecuteError&lt;/A&gt;&lt;SPAN&gt; like any other tool failure. You can trap for that exception class, but you would then want to search the error message strings for error codes from the arcpy.getMessages() array to verify the cancel was what generated the ExecuteError. I'd just try it with your script to find out which particular error code pops up from your cancel, in case it depends on context in your script. For example, if you get error &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00vz00000007085022.htm"&gt;080522&lt;/A&gt;&lt;SPAN&gt; you would scan through the messages for the text " 080522:".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Update:&lt;/STRONG&gt;&lt;SPAN&gt; I tried it this morning and it's true, if a tool isn't running when Cancel is pressed, the script process just dies, with no error message or anything saved in the results. That's not good as it looks like ArcGIS is just zapping the subprocess with a kill. I have no advice, sorry, and hope someone (from Esri) can chime in that knows some of the internals here.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I believe I might be able to use win32api, but I have not figured it out yet. For example:&lt;BR /&gt;win32api.SetConsoleCtrlHandler(func, True)&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I believe this was non-trivial on Windows platforms in the past, but Python 2.6 includes a nifty Popen.kill() method on the &lt;/SPAN&gt;&lt;A href="http://docs.python.org/library/subprocess.html"&gt;subprocess&lt;/A&gt;&lt;SPAN&gt; module.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Apr 2012 04:29:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/close-event-passed-to-python-script-when-canceling/m-p/12701#M1025</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2012-04-12T04:29:34Z</dc:date>
    </item>
  </channel>
</rss>

