[IronPython] how to generate multiple concurrent scriptignengines?

Markus Schaber m.schaber at 3s-software.com
Wed Apr 20 08:23:52 CEST 2011


Hi,

 

You can re-read the thread at http://lists.ironpython.com/pipermail/users-ironpython.com/.

 

The fastest possibility is:

- Fetch the IronPython source.

- Patch PythonContext.GetEqualSite yourself according to the description in the thread.

- Use your own compiled version.

 

Grüße,

Markus

 

Von: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] Im Auftrag von surangika ranathunga
Gesendet: Dienstag, 19. April 2011 04:28
An: Discussion of IronPython; Jeff Hardy
Betreff: Re: [IronPython] how to generate multiple concurrent scriptignengines?

 

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 <jdhardy at gmail.com <mailto:jdhardy at gmail.com> > wrote:

	
	From: Jeff Hardy <jdhardy at gmail.com <mailto:jdhardy at gmail.com> >
	Subject: Re: [IronPython] how to generate multiple concurrent scriptign engines?
	To: "Discussion of IronPython" <users at lists.ironpython.com <mailto:users at lists.ironpython.com> >
	Cc: "surangika ranathunga" <lady_radsu at yahoo.com <mailto:lady_radsu at 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_radsu at yahoo.com <http://nz.mc1102.mail.yahoo.com/mc/compose?to=lady_radsu@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 at lists.ironpython.com <http://nz.mc1102.mail.yahoo.com/mc/compose?to=Users@lists.ironpython.com> 
	> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
	>

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20110420/2b2c5269/attachment.html>


More information about the Ironpython-users mailing list