Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #61132

Re: Embedding multiple interpreters

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <garthy_nhtyp@entropicsoftware.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.019
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'python,': 0.02; 'scripts': 0.03; 'interpreter': 0.05; 'closest': 0.09; 'restriction': 0.09; 'solution,': 0.09; 'python': 0.11; 'thread': 0.14; '"control"': 0.16; 'accesses': 0.16; 'another?': 0.16; 'chris,': 0.16; 'easier.': 0.16; 'enough.': 0.16; 'exhaustive.': 0.16; 'experiment.': 0.16; 'fiddle': 0.16; 'ie.': 0.16; 'interpreter;': 0.16; 'limit.': 0.16; 'normal,': 0.16; 'python-list,': 0.16; 'suggested,': 0.16; 'supplying': 0.16; 'thread,': 0.16; 'wrote:': 0.18; 'do.': 0.18; 'obviously': 0.18; 'bit': 0.19; 'module': 0.19; 'later': 0.20; 'fit': 0.20; 'written': 0.21; 'seems': 0.21; 'issue.': 0.22; 'separate': 0.22; 'header:User-Agent:1': 0.23; "aren't": 0.24; 'case.': 0.24; 'integrate': 0.24; 'cheers,': 0.24; '(or': 0.24; 'script': 0.25; 'header:In-Reply-To:1': 0.27; 'michael': 0.29; 'chris': 0.29; 'ideal': 0.29; 'thus': 0.29; 'dec': 0.30; 'feeds': 0.31; 'run': 0.32; 'another': 0.32; 'running': 0.33; 'fri,': 0.33; 'minimal': 0.33; 'core': 0.34; "i'd": 0.34; 'could': 0.34; 'problem': 0.35; 'received:66': 0.35; "can't": 0.35; 'common': 0.35; 'created': 0.35; 'possible.': 0.35; 'something': 0.35; 'but': 0.35; 'really': 0.36; 'interaction': 0.36; 'whilst': 0.36; 'effort': 0.37; 'application': 0.37; 'level': 0.37; 'easily': 0.37; 'minimum': 0.38; 'sometimes': 0.38; 'problems': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'ability': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'major': 0.40; 'ensure': 0.60; 'skip:u 10': 0.60; 'most': 0.60; 'browser': 0.61; 'skip:* 10': 0.61; 'information,': 0.61; 'simply': 0.61; "you're": 0.61; 'first': 0.61; 'protection': 0.63; 'such': 0.63; 'happen': 0.63; 'provide': 0.64; 'more': 0.64; 'chance': 0.65; 'between': 0.67; 'capable': 0.67; 'yes': 0.68; 'brain': 0.68; 'protect': 0.79; 'bare': 0.84; 'cripple': 0.84; 'entertaining': 0.84; 'interaction.': 0.84; 'interference': 0.84; 'isolate': 0.84; 'malicious': 0.84; 'plugins.': 0.84; 'similar)': 0.84; 'difficult,': 0.91; 'reasons,': 0.91; '2013': 0.98
Date Fri, 06 Dec 2013 20:05:17 +1030
From Garthy <garthy_nhtyp@entropicsoftware.com>
User-Agent Mozilla/5.0 (X11; Linux i686 on x86_64; rv:8.0) Gecko/20111105 Thunderbird/8.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Embedding multiple interpreters
References <mailman.3620.1386298086.18130.python-list@python.org> <bgdat9FouohU1@mid.individual.net> <52A183F8.7000807@entropicsoftware.com> <CAPTjJmq2udX39gxCLjfNWGyeTzMAsHJDHOwXHojNM7Yq18OH7g@mail.gmail.com>
In-Reply-To <CAPTjJmq2udX39gxCLjfNWGyeTzMAsHJDHOwXHojNM7Yq18OH7g@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Mailman-Approved-At Fri, 06 Dec 2013 11:03:35 +0100
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3635.1386324216.18130.python-list@python.org> (permalink)
Lines 73
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1386324216 news.xs4all.nl 2969 [2001:888:2000:d::a6]:48619
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:61132

Show key headers only | View raw


Hi Chris,

On 06/12/13 19:03, Chris Angelico wrote:
 > On Fri, Dec 6, 2013 at 6:59 PM, Garthy
 > <garthy_nhtyp@entropicsoftware.com>  wrote:
 >> Hi Chris (and Michael),
 >
 > Hehe. People often say that to me IRL, addressing me and my brother.
 > But he isn't on python-list, so you clearly mean Michael Torrie, yet
 > my brain still automatically thought you were addressing Michael
 > Angelico :)

These strange coincidences happen from time to time- it's entertaining 
when they do. :)

 >> To allow each script to run in its own environment, with minimal 
chance of
 >> inadvertent interaction between the environments, whilst allowing each
 >> script the ability to stall on conditions that will be later met by 
another
 >> thread supplying the information, and to fit in with existing
 >> infrastructure.
 >
 > Are the scripts written cooperatively, or must you isolate one from
 > another? If you need to isolate them for trust reasons, then there's
 > only one solution, and that's separate processes with completely
 > separate interpreters. But if you're prepared to accept that one
 > thread of execution is capable of mangling another's state, things are
 > a lot easier. You can protect against *inadvertent* interaction much
 > more easily than malicious interference. It may be that you can get
 > away with simply running multiple threads in one interpreter;
 > obviously that would have problems if you need more than one CPU core
 > between them all (hello GIL), but that would really be your first
 > limit. One thread could fiddle with __builtins__ or a standard module
 > and thus harass another thread, but you would know if that's what's
 > going on.

I think the ideal is completely sandboxed, but it's something that I 
understand I may need to make compromises on. The bare minimum would be 
protection against inadvertent interaction. Better yet would be a setup 
that made such interaction annoyingly difficult, and the ideal would be 
where it was impossible to interfere. My approaching this problem with 
interpreters was based on an assumption that it might provide a 
reasonable level of isolation- perhaps not ideal, but hopefully good enough.

The closest analogy for understanding would be browser plugins: Scripts 
from multiple authors who for the most part aren't looking to create 
deliberate incompatibilities or interference between plugins. The 
isolation is basic, and some effort is made to make sure that one plugin 
can't cripple another trivially, but the protection is not exhaustive.

Strangely enough, the GIL restriction isn't a big one in this case. For 
the application, the common case is actually one script running at a 
time, with other scripts waiting or not running at that time. They do 
sometimes overlap, but this isn't the common case. If it turned out that 
only one script could be progressing at a time, it's an annoyance but 
not a deal-breaker. If it's suboptimal (as seems to be the case), then 
it's actually not a major issue.

With the single interpreter and multiple thread approach suggested, do 
you know if this will work with threads created externally to Python, 
ie. if I can create a thread in my application as normal, and then call 
something like PyGILState_Ensure() to make sure that Python has the 
internals it needs to work with it, and then use the GIL (or similar) to 
ensure that accesses to it remain thread-safe? If the answer is yes I 
can integrate such a thing more easily as an experiment. If it requires 
calling a dedicated "control" script that feeds out threads then it 
would need a fair bit more mucking about to integrate- I'd like to avoid 
this if possible.

Cheers,
Garth

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Embedding multiple interpreters Garthy <garthy_nhtyp@entropicsoftware.com> - 2013-12-06 13:04 +1030
  Re: Embedding multiple interpreters Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-12-06 19:58 +1300
    Re: Embedding multiple interpreters Garthy <garthy_nhtyp@entropicsoftware.com> - 2013-12-06 18:29 +1030
      Re: Embedding multiple interpreters Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-12-07 11:09 +1300
        Re: Embedding multiple interpreters Garthy <garthy_nhtyp@entropicsoftware.com> - 2013-12-07 11:27 +1030
    Re: Embedding multiple interpreters Garthy <garthy_nhtyp@entropicsoftware.com> - 2013-12-06 18:51 +1030
    Re: Embedding multiple interpreters Chris Angelico <rosuav@gmail.com> - 2013-12-06 19:33 +1100
    Re: Embedding multiple interpreters Chris Angelico <rosuav@gmail.com> - 2013-12-06 20:27 +1100
    Re: Embedding multiple interpreters Garthy <garthy_nhtyp@entropicsoftware.com> - 2013-12-06 20:05 +1030
      Re: Embedding multiple interpreters Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-12-07 11:23 +1300
        Re: Embedding multiple interpreters Garthy <garthy_nhtyp@entropicsoftware.com> - 2013-12-07 11:01 +1030
    Re: Embedding multiple interpreters Garthy <garthy_nhtyp@entropicsoftware.com> - 2013-12-06 20:14 +1030
    Re: Embedding multiple interpreters Tim Golden <mail@timgolden.me.uk> - 2013-12-06 10:17 +0000
    Re: Embedding multiple interpreters Chris Angelico <rosuav@gmail.com> - 2013-12-06 22:57 +1100
    Re: Embedding multiple interpreters Garthy <garthy_nhtyp@entropicsoftware.com> - 2013-12-07 00:26 +1030
    Re: Embedding multiple interpreters Garthy <garthy_nhtyp@entropicsoftware.com> - 2013-12-07 00:34 +1030

csiph-web