[IronPython] How can I exit from Python Script File?

Mark Grice markjoel60 at gmail.com
Mon Feb 15 22:54:23 CET 2010

I am using IronPython within a C# .NET application.

I have a class that the Python code uses, so I create a scope and set the
variable, then execute the engine like this:

        private ScriptEngine scptEngine = null;
        private ScriptRuntime scptRuntime = null;
        private ScriptScope scptScope;
        private ScriptSource scptSource;

        public pyEngine()

                scptEngine = Python.CreateEngine();
                scptRuntime = scptEngine.Runtime;
                scptScope = scptEngine.CreateScope();
                SOA SOA_screen = new SOA();                 // my Class
                scptScope.SetVariable("screen", SOA_screen);
                scptSource =

This runs fine. But within the Python code, if I detect an error, I want to
exit out of scriptFile.

I check a flag and try to exit if flag is false: so, the basic python is:

   if MessageScreenIsActive == False :
      screen.Say("CAN NOT PROCEED: " + screen.lastResultMessage);

This throws an exception. But this:

   if MessageScreenIsActive == False :
      screen.Say("CAN NOT PROCEED: " + screen.lastResultMessage);

only exits the <IF block> -- not the whole script.

Of course, I can bracket off all of my code with if/else and control it this
way, but there must be a simple way to simple exit the script... isn't

Thanks for reading!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20100215/040b8e1c/attachment.html>

More information about the Ironpython-users mailing list