<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Curt, thanks for the tip. In my tests, I needed to use “from
<modname> import *” since I needed the attributes in the module to
be in the current scope.<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>
<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>
users-bounces@lists.ironpython.com [mailto:users-bounces@lists.ironpython.com] <b>On
Behalf Of </b>Curt Hagenlocher<br>
<b>Sent:</b> Thursday, April 30, 2009 10:31 AM<br>
<b>To:</b> Discussion of IronPython<br>
<b>Subject:</b> Re: [IronPython] Question on Multiple Discrete IronPython
sessions in a single process<o:p></o:p></span></p>
</div>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal style='margin-bottom:12.0pt'>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.<o:p></o:p></p>
<div>
<p class=MsoNormal>On Thu, Apr 30, 2009 at 10:25 AM, Lepisto, Stephen P <<a
href="mailto:stephen.p.lepisto@intel.com">stephen.p.lepisto@intel.com</a>>
wrote:<o:p></o:p></p>
<p class=MsoNormal>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><o:p></o:p></p>
</div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
</body>
</html>