<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.&nbsp; In my tests, I needed to use &#8220;from
&lt;modname&gt; import *&#8221; 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>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</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>&nbsp;</o:p></p>

<p class=MsoNormal style='margin-bottom:12.0pt'>If you import by executing the
text &quot;import &lt;modname&gt;&quot; 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 &lt;<a
href="mailto:stephen.p.lepisto@intel.com">stephen.p.lepisto@intel.com</a>&gt;
wrote:<o:p></o:p></p>

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

</div>

</body>

</html>