[IronPython] IronPython and Threads

Michael Foord fuzzyman at voidspace.org.uk
Sun Jun 8 20:55:18 CEST 2008


Dan Eloff wrote:
>> For now, you'll probably want to wrap any function used as a thread "main" in a try/except and do something to log the error in the exception handler.
>>     
>
> I guess that's what I need to do, seeing as I don't create the thread,
> Silverlight does. Logging/printing is out because it's silverlight.
>
>   

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.

Michael Foord
http://www.ironpythoninaction.com

>> printing to std out isn't too useful in Silverlight but we could also look
>> at having that display in Silverlight somehow too.
>>     
>
> Tell me about it, I'm going to have to think very carefully just to
> find a way to see this error that's bringing everything down. It would
> be great if you guys think of something for Silverlight, (more likely
> just pass the task on to one of the Silverlight guys (Jimmy, are you
> reading this)) because it just silently catches the error, and it's
> very difficult to try to display it, depending on where/when it
> occurs.
>
> -Dan
>
>
> On Sun, Jun 8, 2008 at 12:55 PM, Dino Viehland
> <dinov at exchange.microsoft.com> wrote:
>   
>> If you use the thread module we will wrap the newly created thread in a
>> try/except for you and print to std-out when the unhandled exception
>> occurs.  That way we match the CPython behavior but you can get the standard
>> .NET behavior if you want by going to System.Threading.  Unfortunately
>> printing to std out isn't too useful in Silverlight but we could also look
>> at having that display in Silverlight somehow too.
>>
>>
>>
>> From: users-bounces at lists.ironpython.com
>> [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher
>> Sent: Sunday, June 08, 2008 10:04 AM
>> To: Discussion of IronPython
>> Subject: Re: [IronPython] IronPython and Threads
>>
>>
>>
>> Under CLR 2, any uncaught exception in a thread other than the primary
>> thread will take down the entire process.  This is not specific to
>> IronPython.  I don't know what the Silverlight CLR will do under these
>> circumstances.
>>
>>
>>
>> You could make a case that a Python-initiated thread shouldn't terminate the
>> process given that CPython wouldn't do the same, but as far as I know, we
>> haven't gotten any requests along those lines.  For now, you'll probably
>> want to wrap any function used as a thread "main" in a try/except and do
>> something to log the error in the exception handler.
>>
>> On Sun, Jun 8, 2008 at 8:23 AM, Dan Eloff <dan.eloff at gmail.com> wrote:
>>
>> I'm having a problem debugging some issues that I suspect are thread
>> related in Silverlight. My application is failing silently, so I have
>> no way to be sure yet. Is it possible that exceptions in a background
>> thread are quietly swallowed? I'm pretty sure my callback is being
>> called, but all that is in it right now is a raise statement.
>>
>> I've enabled debug.
>> <param name="initParams" value="debug=true,reportErrors=errorLocation" />
>>
>> I've been trying to explore Threads a little more with IronPython to
>> see what might be the problem, but even there I'm not having much
>> luck. I could swear this used to work in Beta 1. Now it crashes the
>> interpreter.
>>
>> IronPython 2.0 Beta (2.0.0.2000) on .NET 2.0.50727.1433
>> Copyright (c) Microsoft Corporation. All rights reserved.
>>     
>>>>> from System.Threading import Thread, ThreadStart
>>>>> def foo():
>>>>>           
>> ...     raise ValueError
>> ...
>>     
>>>>> t = Thread(ThreadStart(foo))
>>>>> t.Start()
>>>>>
>>>>>           
>> Unhandled Exception: System.ArgumentException
>>   at foo$1##16(Closure )
>>   at _stub_##25(Closure , CallSite , CodeContext , Object )
>>   at Microsoft.Scripting.Utils.InvokeHelper`5.Invoke(Object arg0,
>> Object arg1, Object arg2, Object arg3)
>>   at Microsoft.Scripting.Utils.ReflectedCaller.InvokeInstance(Object
>> instance, Object[] args)
>>   at
>> Microsoft.Scripting.Actions.ActionBinder.UpdateSiteAndExecute[T](CodeContext
>> context, CallSite`1 site, Object[] args)
>>   at Microsoft.Scripting.Actions.UpdateDelegates.Update1[T0,TRet](CallSite
>> site, CodeContext context, T0 arg0)
>>   at System.Void(), using PythonBinder##20(Closure )
>>   at System.Threading.ExecutionContext.Run(ExecutionContext
>> executionContext, ContextCallback callback, Object state)
>>   at System.Threading.ThreadHelper.ThreadStart()
>>
>> What's going wrong? How should I be doing this?
>>
>> Thanks,
>> -Dan
>> _______________________________________________
>> Users mailing list
>> Users at lists.ironpython.com
>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>>
>>
>>
>> _______________________________________________
>> Users mailing list
>> Users at lists.ironpython.com
>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>>
>>
>>     
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>   


-- 
http://www.ironpythoninaction.com/
http://www.theotherdelia.co.uk/
http://www.voidspace.org.uk/
http://www.ironpython.info/
http://www.resolverhacks.net/




More information about the Ironpython-users mailing list