[IronPython] Threading/Delegates
Dan Lash
danlash at gmail.com
Mon Aug 9 21:15:28 CEST 2004
I've just been playing around with IronPython and some of the .NET
framework the past few days, and I tried porting over an example off
of the MSDN library about threading.
The first thing I noticed is that I can't seem to get any class
declarations going. Even this doesn't work:
class Test:
def Hello():
print "Hello"
IronPython gives:
System.Reflection.TargetException: Non-static field requires a target.
at System.Reflection.RuntimeFieldInfo.InternalGetValue(Object obj, Boolean re
quiresAccessCheck)
at System.Reflection.RuntimeFieldInfo.GetValue(Object obj)
at IronPython.Objects.module.__getattribute__(String name)
at IronPython.Objects.ModuleDictionary.get_Item(Object key)
at IronPython.Objects.Frame.GetGlobal(String name)
at input_0.Run(Frame frame)
at IronPythonConsole.IronPython.DoInteractive()
But I guess that may be another issue, what I wanted to get going was
the following:
from System import *
from System.Threading import *
def ThreadProc():
for i in range(10):
Console.WriteLine("ThreadProc: {0}", i)
Thread.Sleep(0)
def Main():
Console.WriteLine("Main thread: Start a second thread.")
t = Thread(ThreadStart(ThreadProc))
t.Start()
for i in range(4):
Console.WriteLine("Main thread: Do some work.")
Thread.Sleep(0)
Console.WriteLine("Main thread: Call Join(), to wait until ThreadProc ends.")
t.Join()
Console.WriteLine("Main thread: ThreadProc.Join has returned.
Press Enter to end program.")
Console.ReadLine()
Which is a port (minus the class) out of:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemthreadingthreadclasstopic.asp
Upon further inspection, it doesn't seem that ThreadStart works on any level:
System.Exception: bad args to this method <constructor# for
System.Threading.ThreadStart>
at IronPython.Objects.ReflectedMethodBase.Call(Object[] args)
at IronPython.Objects.ReflectedType.Call(Object[] args)
at IronPython.Objects.Ops.Call(Object func, Object arg0)
at input_3.Main$f1()
at IronPython.Objects.Function0.Call()
at IronPython.Objects.Ops.Call(Object func)
at input_5.Run(Frame frame)
at IronPythonConsole.IronPython.DoInteractive()
Am I missing something here, is my Python syntax wrong? Or is
IronPython just not ready for ThreadStart delegates?
More information about the Ironpython-users
mailing list