Hi, Sorry I missed the posts on this thread. This is the code that caused me the problem (I posted this in the first post of the thread) So according to your mails, I take that this is due to a bug in the ironpython code. Is there a way I can have some alternative work-out, something that I can do through my code? (i'm in kind of a hury to finish the project :S ) ScriptEngine engine = Python.CreateEngine(); ScriptRuntime runtime = engine.Runtime; ScriptScope scope = runtime.CreateScope(); ops = engine.Operations;
try { ScriptSource source = engine.CreateScriptSourceFromFile("ironpython.py"); source.Execute(scope); string class_param = rule; object[] parameters = new object[1]; parameters[0] = class_param; object klass = scope.GetVariable("model_checker"); object instance = ops.Invoke(klass, parameters); method = ops.GetMember(instance, "check_model"); } catch (Exception e) { Console.WriteLine(e.ToString()); } --- On Thu, 14/4/11, Jeff Hardy <jdha...@gmail.com> wrote: From: Jeff Hardy <jdha...@gmail.com> Subject: Re: [IronPython] how to generate multiple concurrent scriptign engines? To: "Discussion of IronPython" <users@lists.ironpython.com> Cc: "surangika ranathunga" <lady_ra...@yahoo.com> Received: Thursday, 14 April, 2011, 7:35 AM As long as you have a ScriptScope per thread, you should be able to share the ScriptEngine & Runtime between threads. What is the exception that you are getting? If it's a GUI program, remember that UI elements can only be manipulated from the main thread. - Jeff On Thu, Apr 14, 2011 at 1:02 AM, surangika ranathunga <lady_ra...@yahoo.com> wrote: > > Hi, > I am using Ironpython to connect to a legacy python code from C#. > I am not fully familiar with Ironpython, but managed to get it working for a > single-threaded application. > This is how I implemented this: > > ScriptEngine engine = Python.CreateEngine(); > ScriptRuntime runtime = engine.Runtime; > ScriptScope scope = runtime.CreateScope(); > ops = engine.Operations; > ScriptSource source = > engine.CreateScriptSourceFromFile("ironpython.py"); > source.Execute(scope); > string class_param = rule; > object[] parameters = new object[1]; > parameters[0] = class_param; > object klass = scope.GetVariable("model_checker"); > object instance = ops.Invoke(klass, parameters); > method = ops.GetMember(instance, "check_model"); > > Now I want to make my application multi-threaded, and I want to have > concurrently running scripting engines. Essentially, these engines should > access the same underlying python code, and hence these scripting engines are > identical to each other. > Without any change, the above code works fine for most of the time for a > multi-threaded application. However, there is an exception that appears from > time to time, and I suspect that it is due to a concurrency issue. > > Is there anything specific that I should do to generate multiple scripting > engines running in separate threads without interfering with each other? > > any ideas greatly appreciated > > _______________________________________________ > Users mailing list > Users@lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >
_______________________________________________ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com