<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<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 name=Generator content="Microsoft Word 14 (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:0cm;
        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;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></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=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>This is one of the things I’d have liked to see as part of py3k:  “fixing” python for embedding in applications and defices.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>It would have meant getting rid of all globals and statics and tracking them in some sort of “context” structure.  Since you’d have to change the C API, you could take the opportunity to fix some of its ugliest warts, such as inconsistent reference counting semantics between methods (making it difficult to write good smart pointer wrappers for it, as in COM.  COM has very simple, clear and universal reference counting rules).<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>K<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><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"'> python-ideas-bounces+kristjan=ccpgames.com@python.org [mailto:python-ideas-bounces+kristjan=ccpgames.com@python.org] <b>On Behalf Of </b>Swapnil Talekar<br><b>Sent:</b> Wednesday, November 17, 2010 22:46<br><b>To:</b> Chris Rebert; python-ideas@python.org<br><b>Subject:</b> [Python-ideas] In-process interpreters<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal style='margin-bottom:12.0pt'><o:p> </o:p></p><div><p class=MsoNormal>On Wed, Nov 17, 2010 at 2:11 PM, Chris Rebert <<a href="mailto:pyideas@rebertia.com">pyideas@rebertia.com</a>> wrote:<o:p></o:p></p><div><p class=MsoNormal style='margin-bottom:12.0pt'>On Wed, Nov 17, 2010 at 12:26 AM, Swapnil Talekar <<a href="http://swapnil.st" target="_blank">swapnil.st</a>@<a href="http://gmail.com" target="_blank">gmail.com</a>> wrote:<br>> I am working on a project where we have a very peculiar requirements for an<br>> embedded interpreter. In my opinion these requirements cannot be extremely<br>> rare. I am posting this message to get some feedback from people who have<br>> worked on similar stuff or are interested in such a solution. If such a<br>> solution would be useful to a lot people if readily available as open<br>> source.<br>> We need to run multiple interpreters in-process. Which means we need to<br>> create completely independent environments for each interpreter using some<br>> very dirty hack. Since Python inherently does not support this. Python<br>> threads( created using python's threading module ) are not of much help<br>> because of the GIL.<br>> For this purpose the solution we have adopted is moving all the mutable<br>> python globals to heap.<br>> Nokia did a similar change to Python while porting it to S60 platform.<br>> Reference<br>> It seems Nokia has stopped using this solution but I am not aware of how are<br>> they going about now since I cannot think of any other solution to run<br>> multiple in-process interpreters. Jukka, can you throw some light ?<br>> Lua already supports this.<br>> I would expect other projects like mod_python would also have to face<br>> similar problem but I am not aware how they are handling it.<o:p></o:p></p></div><p class=MsoNormal>It used* "sub-interpreters" apparently:<br><a href="http://modpython.org/live/current/doc-html/pyapi-interps.html" target="_blank">http://modpython.org/live/current/doc-html/pyapi-interps.html</a><br><a href="http://docs.python.org/c-api/init.html#Py_NewInterpreter" target="_blank">http://docs.python.org/c-api/init.html#Py_NewInterpreter</a><o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Sub-interpreters aren't attractive for the very reasons given in the Bugs and caveats section of the above link. Moreover Sub-interpreters do not release memory (as far as I have tested) even after calling Py_EndInterpreter. This makes them unusable on platforms with high memory constraint.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div></div></div></body></html>