# How to properly stop a python plugin by Esc

**URL:** <https://discourse.mcneel.com/t/how-to-properly-stop-a-python-plugin-by-esc/7452>\
**Category:** Scripting\
**Created:** [April 11, 2014, 7:33am UTC](https://discourse.mcneel.com/t/how-to-properly-stop-a-python-plugin-by-esc/7452 "2014-04-11T07:33:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Holo](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/holo/32/496872_2.png) [@Holo](https://discourse.mcneel.com/u/Holo)\
**Post date:** [April 11, 2014, 7:33am UTC](https://discourse.mcneel.com/t/how-to-properly-stop-a-python-plugin-by-esc/7452/1 "2014-04-11T07:33:24Z")

</div>

Hi, I need some help to understand how to properly terminate a Python script when it is converted to a plugin.

I made a dummy scipt that works when ran from the editor, but not as a plugin:

```python

import rhinoscriptsyntax as rs
import scriptcontext
import Rhino

def CheckForESCpress():
    if scriptcontext.escape_test(False):
        rs.AddText("Command terminated by ESC", (-20,2,0), height=2, font="Century Gothic", font_style=1, justification=None)
        rs.DeleteObject(textId)
        return True

textId=rs.AddText ( ".", (-18,0,0), height=2, font="Century Gothic", font_style=1, justification=None )
rs.RotateObject(textId,(0,0,0),rotation_angle=-20,axis=None, copy=False)
n=200
for i in range (n):
    rs.RotateObject(textId,(0,0,0),rotation_angle=0.2,axis=None, copy=False)
    rs.MoveObject(textId,(0,-0.02,0))
    rs.TextObjectText (textId, "Press ESC to terminate - "+str(n-1-i))
    Rhino.RhinoApp.Wait()
    
    CheckForESCpress()

rs.DeleteObject (textId)
rs.AddText ( "ESC was not registered", (-18,0,0), height=2, font="Century Gothic", font_style=1, justification=None )

```

Here is the compiled script where pressing ESC doesn’t give me the desired result.
