[IronPython] IronPython and Threads
Dan Eloff
dan.eloff at gmail.com
Mon Jun 9 02:20:59 CEST 2008
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
startup()
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?
Thanks,
-Dan
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
>
More information about the Ironpython-users
mailing list