[IronPython] IronPython and Threads

Dino Viehland dinov at exchange.microsoft.com
Mon Jun 9 02:44:23 CEST 2008

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.

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Dan Eloff
Sent: Sunday, June 08, 2008 5:21 PM
To: Discussion of IronPython
Subject: Re: [IronPython] IronPython and Threads

Ok I've been at this all day, and I've discovered some nifty things.
It was pretty trivial to redirect output to an html textarea. The html
markup/styling gave me way more trouble than the managed code (I
really hate html.)

The big find though was the Application.Current.UnhandledException event.

def excepthook(sender, e):
    print e.ExceptionObject

def startup():
    import sys
    sys.stdout = sys.stderr = DebugStream()

    Application.Current.UnhandledException += excepthook

    # start application


Which will print unhandled exceptions, even ones that occur in
background threads!

But of course this prints a .NET traceback, which is pretty much
useless for IronPython. But surely there is some way to print a python
exception once I have this .NET exception object?


On Sun, Jun 8, 2008 at 2:22 PM, Dan Eloff <dan.eloff at gmail.com> wrote:
> Michael Foord Wrote:
>> In my IronPython Web IDE I divert standard out and redirect it to an html
>> textarea so that I can see everything that is printed. This is very useful
>> for debugging.
>> If you are doing this from threads you ought to use a dispatcher to add the
>> text to the htmlarea - but it is very easy.
> I redirect stdout and stderr to an interactive python console in
> silverlight, but it does me no good here because this is happening
> before the console loads. So I think I will need to create an html
> textarea like you suggested to handle any output before the console
> loads.
> -Dan
Users mailing list
Users at lists.ironpython.com

More information about the Ironpython-users mailing list