[IronPython] IP v8 Hosting question...

Alex Henderson alex at syzmk.com
Wed Jun 28 03:19:47 CEST 2006


Yeah, I arrived at this yesterday after some experimentation :) I've since
dumped the idea of setting global variables (as it's obviously not thread
safe for multiple threads evaluating the same expression) and now generate
methods for the expression i.e.

For an expression:   "Hello" + Message

I would end up generating

def generated_method_1(Message):
	return "Hello" + Message

Then execute that against a newly created module, then evaluate
"generated_method_1", casting it to a PythonFunction and Call that
with the array of values that make up my context... works well now and suits
my needs perfectly as I can wrap up iron python to work with our standard
scripting interfaces. 

When I no longer need these methods I set their value to None, but I'm
wondering if generating methods like this will incur overhead I can't get
back (ie. will my apps memory consumption just keep growing, until the
python engine itself is shut down?) It certainly seems a little like that
when I've been unit testing, but perhaps that's a side effect of the NUnit
environment?

Chez,

 - Alex

> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-
> bounces at lists.ironpython.com] On Behalf Of Shri Borde
> Sent: Wednesday, 28 June 2006 9:55 a.m.
> To: Discussion of IronPython
> Subject: Re: [IronPython] IP v8 Hosting question...
> 
> We will are taking a look at the API and will be changing it a bit.
> 
> The current way of doing this as follows:
> 
> PythonEngine engine = new PythonEngine();
> 
> SymbolId id = SymbolTable.StringToId("Message");
> 
> ModuleScope scope1 = new ModuleScope("Junk1");
> scope1.SetGlobal(id, "hello");
> 
> ModuleScope scope2 = new ModuleScope("Junk2");
> scope2.SetGlobal(id, "goodbye");
> 
> Assert.AreEqual("hello", engine.Evaluate<string>("Message", scope1,
> ExecutionOptions.Default));
> 
> Assert.AreEqual("goodbye", engine.Evaluate<string>("Message", scope2,
> ExecutionOptions.Default));
> 
> Do you want to help develop Dynamic languages on CLR?
> (http://members.microsoft.com/careers/search/details.aspx?JobID=6D4754DE-
> 11F0-45DF-8B78-DC1B43134038)
> 
> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-
> bounces at lists.ironpython.com] On Behalf Of Alex Henderson
> Sent: Monday, June 26, 2006 5:03 PM
> To: 'Discussion of IronPython'
> Subject: [IronPython] IP v8 Hosting question...
> 
> I'm looking for the most appropriate way to "scope" variables for my
> expression to evaluate that come from an external context (ie. Outside of
> the python engine) - So far I have something working, using ModuleScope -
> but is this the way I should be doing it?
> 
> PythonEngine engine = new PythonEngine();
> 
> SymbolId id = SymbolTable.StringToId("Message");
> 
> ModuleScope scope1 = ModuleScope.MakeScopeForFunction(new
> PythonModule("Junk", new Dict(), engine.Sys));
> scope1.SetGlobal(id, "hello");
> 
> ModuleScope scope2 = ModuleScope.MakeScopeForFunction(new
> PythonModule("Junk", new Dict(), engine.Sys));
> scope2.SetGlobal(id, "goodbye");
> 
> Assert.AreEqual("hello", engine.Evaluate<string>("Message", scope1,
> ExecutionOptions.Default));
> 
> Assert.AreEqual("goodbye", engine.Evaluate<string>("Message", scope2,
> ExecutionOptions.Default));
> 
> Using this method I can evaluate around 2000 expressions a second, which
> is
> more the adequate for what I'm doing - but I'm concerned about memory
> consumption...
> 
> Chez,
> 
>  - Alex
> 
> _______________________________________________
> 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




More information about the Ironpython-users mailing list