If you import by executing the text "import <modname>" against the ScriptEngine instead of using the import API, you will avoid this particular incarnation of the bug.<br><br><div class="gmail_quote">On Thu, Apr 30, 2009 at 10:25 AM, Lepisto, Stephen P <span dir="ltr"><<a href="mailto:stephen.p.lepisto@intel.com">stephen.p.lepisto@intel.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">I voted for fixing the bug. In the meantime, I will be putting on hold the use of IronPython as an embedded language in my project until this is fixed or IronPython 2.6 is released (if I can convince my manager and team it's a good idea to move to python 2.6 but it will affect a lot of people).<br>
<br>
Thank you for the prompt responses!<br>
<br>
<br>
-----Original Message-----<br>
From: <a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a> [mailto:<a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a>] On Behalf Of Dino Viehland<br>
Sent: Thursday, April 30, 2009 10:23 AM<br>
To: Discussion of IronPython<br>
Subject: Re: [IronPython] Question on Multiple Discrete IronPython sessions in a single process<br>
<br>
Looks like our threads crossed. Yep, I was using the current 2.6 branch.<br>
<br>
I opened a bug to fix this in 2.0.2 (<a href="http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=22239" target="_blank">http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=22239</a>).<br>
<br>
Thanks for reporting this - this is a very bad bug.<br>
<br>
> -----Original Message-----<br>
> From: <a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a> [mailto:<a href="mailto:users-">users-</a><br>
> <a href="mailto:bounces@lists.ironpython.com">bounces@lists.ironpython.com</a>] On Behalf Of Lepisto, Stephen P<br>
> Sent: Thursday, April 30, 2009 10:10 AM<br>
> To: Discussion of IronPython<br>
> Subject: Re: [IronPython] Question on Multiple Discrete IronPython<br>
> sessions in a single process<br>
><br>
> Dino,<br>
><br>
> That example you provided produced the following output under<br>
> IronPython 2.0.1:<br>
><br>
> hello<br>
> 42<br>
><br>
> In other words, the two sessions appear to be sharing the same module<br>
> in IronPython 2.0.1.<br>
><br>
> Are you using a later version of IronPython where this might be fixed?<br>
><br>
><br>
> -----Original Message-----<br>
> From: <a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a> [mailto:<a href="mailto:users-">users-</a><br>
> <a href="mailto:bounces@lists.ironpython.com">bounces@lists.ironpython.com</a>] On Behalf Of Dino Viehland<br>
> Sent: Thursday, April 30, 2009 9:28 AM<br>
> To: Discussion of IronPython<br>
> Subject: Re: [IronPython] Question on Multiple Discrete IronPython<br>
> sessions in a single process<br>
><br>
> And this works for me:<br>
><br>
> using System;<br>
> using IronPython.Hosting;<br>
> using Microsoft.Scripting.Hosting;<br>
><br>
> class foo {<br>
> static void Main(string[] args)<br>
> {<br>
> var engine = Python.CreateEngine();<br>
> ScriptScope scope1 = engine.ImportModule("foo");<br>
><br>
> var engine2 = Python.CreateEngine();<br>
> ScriptScope scope2 = engine2.ImportModule("foo");<br>
><br>
> scope1.SetVariable("foo", 42);<br>
> object res;<br>
> if(scope2.TryGetVariable("foo", out res)) {<br>
> Console.WriteLine(res);<br>
> } else {<br>
> Console.WriteLine("no foo");<br>
> }<br>
> }<br>
> }<br>
><br>
> Foo.py:<br>
> print 'hello'<br>
><br>
> Printing out:<br>
><br>
> hello<br>
> hello<br>
> no foo<br>
><br>
> > -----Original Message-----<br>
> > From: <a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a> [mailto:<a href="mailto:users-">users-</a><br>
> > <a href="mailto:bounces@lists.ironpython.com">bounces@lists.ironpython.com</a>] On Behalf Of Michael Foord<br>
> > Sent: Thursday, April 30, 2009 9:08 AM<br>
> > To: Discussion of IronPython<br>
> > Subject: Re: [IronPython] Question on Multiple Discrete IronPython<br>
> > sessions in a single process<br>
> ><br>
> > Dino Viehland wrote:<br>
> > ><br>
> > > You mention CreateEngine but are you also creating multiple<br>
> runtimes?<br>
> > > You're only allowed 1 ScriptEngine of a given type per<br>
> ScriptRuntime.<br>
> > > So you should create a new ScriptRuntime and then get the Python<br>
> > > engine for each runtime and then be isolated.<br>
> > ><br>
> ><br>
> > If you call Python.CreateEngine() twice it gives you two different<br>
> > engine objects with what *appear* to be different runtimes.<br>
> ><br>
> > If you then call Python.ImportModule for the same module but passing<br>
> in<br>
> > the two different engines, you get two different (non-identical<br>
> > objects)<br>
> > ScriptScopes - but changes in one are reflected in the other.<br>
> ><br>
> > Is CreateEngine not the correct way to get isolated engines?<br>
> ><br>
> > Michael<br>
> ><br>
> > > *From:* <a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a><br>
> > > [mailto:<a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a>] *On Behalf Of *Lepisto,<br>
> > > Stephen P<br>
> > > *Sent:* Thursday, April 30, 2009 8:26 AM<br>
> > > *To:* <a href="mailto:users@lists.ironpython.com">users@lists.ironpython.com</a><br>
> > > *Subject:* [IronPython] Question on Multiple Discrete IronPython<br>
> > > sessions in a single process<br>
> > ><br>
> > > Hello, everyone!<br>
> > ><br>
> > > I am working on an service manager application that provides<br>
> embedded<br>
> > > python support through a small set of generalized classes:<br>
> > > PythonService, PythonSession, and PythonClass. A client application<br>
> > > asks the service manager for the PythonService object and then asks<br>
> > > the PythonService object for a new PythonSession object. The<br>
> > > PythonSession object is used to access embedded python through a<br>
> > small<br>
> > > set of generalized methods. The PythonClass object is used to wrap<br>
> a<br>
> > > python class instance.<br>
> > ><br>
> > > The key requirement in this is each client must have its own python<br>
> > > session, independent of any other sessions currently running. I've<br>
> > got<br>
> > > this to work with CPython (specifically, python 2.5.4), by careful<br>
> > use<br>
> > > of the global interpreter lock and swapping the thread state.<br>
> > > IronPython 2.0.1 has a nicer way of implementing all of this by<br>
> using<br>
> > > the CreateEngine() to create a new python engine. However, in<br>
> > > IronPython I've run into what appears to be a significant<br>
> limitation<br>
> > > that may prevent me from using IronPython in this particular<br>
> > situation<br>
> > > as an embedded language.<br>
> > ><br>
> > > The limitation is when I import a python package from disk into<br>
> > > IronPython (using IronPython.Hosting.Python.ImportModule()) in one<br>
> > > session and then import the same package into a different session,<br>
> it<br>
> > > turns out that both sessions are pulling from the same module's<br>
> > scope.<br>
> > > That is, if I make changes to the module's scope in one session<br>
> (for<br>
> > > example, changing a global variable), that change appears in the<br>
> > other<br>
> > > session.<br>
> > ><br>
> > > After tracing execution in the IronPython 2.0.1 code, it turns out<br>
> > > that a module is cached in the LanguageContext (PythonContext)<br>
> > object,<br>
> > > which in turn is a singleton in DLR, as it is associated with the<br>
> > > language type. This is okay if an application is embedding<br>
> IronPython<br>
> > > itself but in my scenario, this prevents multiple discrete python<br>
> > > sessions in a single application. Ideally, I would expect to see<br>
> the<br>
> > > system state be stored in the python engine (ScriptEngine) or<br>
> python<br>
> > > runtime (ScriptRuntime) objects.<br>
> > ><br>
> > > Is there a way around this limitation? Can I somehow create a<br>
> unique<br>
> > > PythonContext object for each of my python sessions so I get a<br>
> > > completely discrete python instance in each session with no<br>
> > crosstalk?<br>
> > > Or do I have to resort to modifying the IronPython source to<br>
> > > accomplish this (which I'm loathe to do since then I would have to<br>
> > > maintain it going forward)?<br>
> > ><br>
> > > Thank you for your time and consideration in this matter.<br>
> > ><br>
> > > -------------------------------------------------------------------<br>
> --<br>
> > ---<br>
> > ><br>
> > > _______________________________________________<br>
> > > Users mailing list<br>
> > > <a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
> > > <a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
> > ><br>
> ><br>
> ><br>
> > --<br>
> > <a href="http://www.ironpythoninaction.com/" target="_blank">http://www.ironpythoninaction.com/</a><br>
> ><br>
> > _______________________________________________<br>
> > Users mailing list<br>
> > <a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
> > <a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
><br>
> _______________________________________________<br>
> Users mailing list<br>
> <a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
> <a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
> _______________________________________________<br>
> Users mailing list<br>
> <a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
> <a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
</blockquote></div><br>