[IronPython] function thread target delegates

Anthony Tarlano mailinglist.account at gmail.com
Sat Aug 6 22:01:41 CEST 2005


Keith,

Thanks for your insight and reply. 

I found that it works if instead of using generics, I just wrapped the
function as an ParameterizedThreadStart instance.. Take a look:

Anthony

IronPython 0.9.2036 on .NET 2.0.50215.44
Copyright (c) Microsoft Corporation. All rights reserved.
>>> from System import Threading
>>> def echo(arg):
...   print arg
...
>>> t = Threading.Thread(Threading.ParameterizedThreadStart(echo))
>>> t.Start('hi')
>>> hi

()
>>>



On 8/6/05, Keith J. Farmer <kfarmer at thuban.org> wrote:
> Okay, had a brief check.  You should take a look at delegates.  They're
> not the same as passing around Python methods.  In particular, they're
> typed.
> The type of a delegate is its signature.  In particular:
> ThreadStart -> void foo()
> ParameterizedThreadStart -> void foo(object)
> The Thread constructor you're picking up is Thread(ThreadStart foo),
> where you want Thread(ParameterizedThreadStart foo).
> What you want, somehow, is to get the overload to pick the
> ParameterizedThreadStart version.
> However, the following seems to encounter a conflict between generics
> and method resolution:
> >>> t = Threading.Thread[Threading.ParameterizedThreadStart](echo)
> System.InvalidOperationException: System.Threading.Thread is not a
> GenericTypeDefinition. MakeGenericType may only be called on a type for
> which Type.IsGenericTypeDefinition is true.
>    at System.RuntimeType.MakeGenericType(Type[] instantiation, Boolean
> verify)
>    at input_11.Run(Frame frame)
> 
> -----
> Keith J. Farmer
> kfarmer at thuban.org
> _______________________________________________
> users-ironpython.com mailing list
> users-ironpython.com at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>



More information about the Ironpython-users mailing list