[IronPython] IronPython and Threads

Dan Eloff dan.eloff at gmail.com
Mon Jun 9 03:18:27 CEST 2008

On Sun, Jun 8, 2008 at 7:44 PM, Dino Viehland
<dinov at exchange.microsoft.com> wrote:
> There's a DLR hosting API for formatting exceptions - ScriptEngine.FormatException.
> >From Silverlight I think you can access the DynamicApplication class, in Microsoft.Scripting.Silverlight, which gives you access to the current ScriptRuntime .  You might need a clr.AddReference to Microsoft.Scripting.Silverlight in there.  From there you can get the ScriptEngine for Python and then call FormatException on the exception object.  And that will give you the Python stack trace as we normally display it.

def excepthook(sender, e):
    print Application.Current.Environment.GetEngine('py').FormatException(e.ExceptionObject)

Thanks! Works like a charm. Now I see exceptions on any thread without
having to add try/except clauses all over. Btw, is there anywhere to
get documentation on things like ScriptRuntime? I had to dig through
the IronPython source to figure out how to get the engine.

Many thanks to everyone here who took the time to respond on Sunday!


More information about the Ironpython-users mailing list