Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

19 May, 2024: Line wrapping has been changed to be more consistent with Usenet standards.
 If you find that it is broken please let me know here rocksolid.nodes.help


devel / comp.lang.python / Why does IDLE use a subprocess?

SubjectAuthor
* Why does IDLE use a subprocess?James Schaffler
`* Why does IDLE use a subprocess?Greg Ewing
 +- Why does IDLE use a subprocess?James Schaffler
 +- Why does IDLE use a subprocess?Chris Angelico
 `- Why does IDLE use a subprocess?James Schaffler

1
Why does IDLE use a subprocess?

<mailman.27.1685477273.23016.python-list@python.org>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=23461&group=comp.lang.python#23461

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: jschaffler@proton.me (James Schaffler)
Newsgroups: comp.lang.python
Subject: Why does IDLE use a subprocess?
Date: Sun, 28 May 2023 20:10:02 +0000
Lines: 25
Message-ID: <mailman.27.1685477273.23016.python-list@python.org>
References: <0yjTTMo6f2sNAeHM8DWbLsJ3Yh3N1Fc-9MUmGXN4PoQ7rh3ovCCCEDrEb-UkCDWxIfwO1KaLP8WS2QMGtWz7phfJOU4rH-uhW5X8Wov-xEU=@proton.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de yx+BBy45SzcKl/uDnNuWzQjJqUADxLkXcckbzStH6qvw==
Return-Path: <jschaffler@proton.me>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=proton.me header.i=@proton.me header.b=WcmVNtl6;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.014
X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; '(which': 0.04; 'knows':
0.04; 'subject:Why': 0.07; 'idle': 0.09; 'originally': 0.09;
"shouldn't": 0.09; 'subject:IDLE': 0.09; 'idle,': 0.16;
'interpreter': 0.16; "isn't.": 0.16; 'isolated': 0.16;
'subject:does': 0.16; 'python': 0.16; 'says': 0.17; 'uses': 0.19;
'to:addr:python-list': 0.20; 'version': 0.23; 'code': 0.23; "i'd":
0.24; 'to:name:python-list@python.org': 0.24; 'anyone': 0.25;
'object': 0.26; 'received:185.70': 0.26; 'received:protonmail.ch':
0.26; 'question': 0.32; 'modified': 0.32; 'received:185.70.40':
0.32; 'window': 0.32; 'but': 0.32; "i'm": 0.33; 'able': 0.34;
'running': 0.34; 'received:ch': 0.35; 'runs': 0.35; 'really':
0.37; 'could': 0.38; 'sending': 0.39; 'use': 0.39; 'place.': 0.40;
'view': 0.60; 'skip:i 20': 0.62; 'security': 0.64; 'let': 0.66;
'coloring': 0.69; 'received:185': 0.71; 'combination': 0.76;
'leads': 0.81; 'header:Received:2': 0.84; '(please': 0.84; '"why':
0.91; 'affect': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me;
s=protonmail; t=1685304608; x=1685563808;
bh=WJ4wZQqgVDuiDR+BTzp2zjAfnX0/YNOkKDJdBcwcb0Y=;
h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date:
Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector;
b=WcmVNtl6/y4d4I/Res+7U9MOMnGXVQXhc6sXCqduaYPf+IG9SdY80BMF6kYKcZhkX
Kz+YaOYiaxJ3FJzb++k49ZWddPmdxuHNO9vXrjCBGCV1GIgnj2zm5b7rZViThHqg4v
mWLkOCNXGj54QbtwvtRiWpFDlXT6jQzbPH9jPyhGQxbZuX3+8e4K5NcajOwnfuvpDQ
3xP59YxOrhlWrKitnB0X/2SP/bGPqa+ahBpDVcM50c6XFAlW2MJpmyIBqCY87ccSYn
bINqv+c7EKZ3GDowHUF3Ab2u4Z6nOvhba6k7ASLZD9M6217a/u9eBgbUcryS/XOD1l
S97Zt4+O0pSOQ==
Feedback-ID: 75857154:user:proton
X-Mailman-Approved-At: Tue, 30 May 2023 16:07:52 -0400
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
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: <https://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>
X-Mailman-Original-Message-ID: <0yjTTMo6f2sNAeHM8DWbLsJ3Yh3N1Fc-9MUmGXN4PoQ7rh3ovCCCEDrEb-UkCDWxIfwO1KaLP8WS2QMGtWz7phfJOU4rH-uhW5X8Wov-xEU=@proton.me>
 by: James Schaffler - Sun, 28 May 2023 20:10 UTC

Originally posted to idle-dev, but thought this might be a better place. Let me know if it isn't.

Hi,

I was curious about the internals of IDLE, and noticed that IDLE uses executes user code in a "subprocess" that's separate from the Python interpreter that is running IDLE itself (which does tasks such as making the window and coloring the text).

As far as I understand, IDLE runs a modified version of code.InteractiveInterpreter by sending user code through a socket. Even the IDLE documentation says that without a subprocess, "user code is not isolated from IDLE itself." However, some minimal testing of InteractiveInterpreter leads me to believe that the Interpreter object has its own view of local/global variables and therefore shouldn't be able to affect the calling interpreter (please correct me if I'm wrong).

So my question is a combination of "Why does IDLE use a subprocess?" and "Why is InteractiveInterpreter not secure enough?" What possible security vulnerabilities exist if one uses IDLE without the subprocess? If anyone knows (or could point me to information on) why IDLE is designed this way, I'd really appreciate it. Thank you!

Jim

Re: Why does IDLE use a subprocess?

<kdnlc4Fgl4fU1@mid.individual.net>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=23474&group=comp.lang.python#23474

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!lilly.ping.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: greg.ewing@canterbury.ac.nz (Greg Ewing)
Newsgroups: comp.lang.python
Subject: Re: Why does IDLE use a subprocess?
Date: Wed, 31 May 2023 13:14:40 +1200
Lines: 22
Message-ID: <kdnlc4Fgl4fU1@mid.individual.net>
References: <0yjTTMo6f2sNAeHM8DWbLsJ3Yh3N1Fc-9MUmGXN4PoQ7rh3ovCCCEDrEb-UkCDWxIfwO1KaLP8WS2QMGtWz7phfJOU4rH-uhW5X8Wov-xEU=@proton.me>
<mailman.27.1685477273.23016.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net YWM6QV33UGzEmNMCL4NNJgbSysMneoqFZyw1kpCrgLxEc5zMkR
Cancel-Lock: sha1:X0zlESJ6Te5CO0jJ2ppnGmAlRyM=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:91.0)
Gecko/20100101 Thunderbird/91.3.2
Content-Language: en-US
In-Reply-To: <mailman.27.1685477273.23016.python-list@python.org>
 by: Greg Ewing - Wed, 31 May 2023 01:14 UTC

On 29/05/23 8:10 am, James Schaffler wrote:
> However, some minimal testing of InteractiveInterpreter leads me to believe that the Interpreter object has its own view of local/global variables and therefore shouldn't be able to affect the calling interpreter

Globals you create by executing code in the REPL have their own
namespace. But everything else is shared -- builtins, imported
Python modules, imported C extension modules, etc. etc.

There's a long-running project to make it possible to have
multiple fully-isolated Python interpreters in one process, but
the way CPython is structured makes that very difficult to achieve,
and as far as I know it's not there yet.

In the case of IDLE, there's really no reason not to use a
subprocess[1]. It's easy and guarantees 100% isolation.

[1] Well, mostly. There used to be a small hitch on Windows with
the default firewall settings not letting you connect to a local
socket (nice one, Microsoft). I don't know whether that's still
an issue.

--
Greg

Re: Why does IDLE use a subprocess?

<mailman.36.1685498498.23016.python-list@python.org>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=23475&group=comp.lang.python#23475

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: jschaffler@proton.me (James Schaffler)
Newsgroups: comp.lang.python
Subject: Re: Why does IDLE use a subprocess?
Date: Wed, 31 May 2023 02:01:25 +0000
Lines: 24
Message-ID: <mailman.36.1685498498.23016.python-list@python.org>
References: <0yjTTMo6f2sNAeHM8DWbLsJ3Yh3N1Fc-9MUmGXN4PoQ7rh3ovCCCEDrEb-UkCDWxIfwO1KaLP8WS2QMGtWz7phfJOU4rH-uhW5X8Wov-xEU=@proton.me>
<mailman.27.1685477273.23016.python-list@python.org>
<kdnlc4Fgl4fU1@mid.individual.net>
<SJXiQDnGka3VfQRZVMeoW3ssdKe3sT0t7qyh0dxS-LFrOQnT2qePsmq6em0P1cY1wwvPwEbCOTjGwEC5M-5UqC9BmnyFAW4JvwhiKgQ9gS0=@proton.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de aofjCb5kP9o3EOkAJZA2twbw55iHiryEjDqS2UK5ypHg==
Return-Path: <jschaffler@proton.me>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=proton.me header.i=@proton.me header.b=fCBB61Rt;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'traceback': 0.04; '(most':
0.05; 'last):': 0.05; '2023': 0.07; 'parent': 0.07; 'subject:Why':
0.07; 'cc:addr:python-list': 0.09; 'numpy': 0.09; 'subject:IDLE':
0.09; 'cc:no real name:2**0': 0.14; 'import': 0.15; 'elaborate':
0.16; 'greg': 0.16; 'modules,': 0.16; 'received:mail-europe.com':
0.16; 'subject:does': 0.16; 'swap': 0.16; 'versa': 0.16; 'wrote:':
0.16; 'python': 0.16; 'pm,': 0.19; 'cc:addr:python.org': 0.20;
'code': 0.23; 'run': 0.23; 'extension': 0.25; 'cc:2**0': 0.25;
'seems': 0.26; 'else': 0.27; 'error': 0.29; '"",': 0.32; 'but':
0.32; 'header:In-Reply-To:1': 0.34; 'following': 0.35; 'thanks,':
0.36; 'file': 0.38; 'could': 0.38; 'thanks': 0.38; 'shared': 0.39;
'skip:i 20': 0.62; 'everything': 0.63; 'header:Received:2': 0.84;
'executing': 0.84; 'imports': 0.84; 'interpreters': 0.84;
'received:188.165': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me;
s=protonmail; t=1685498489; x=1685757689;
bh=QgMHoGCMWh8EIe0VyShIHyndbh4WDw5ir+mqr0p5cNU=;
h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References:
Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID:
Message-ID:BIMI-Selector;
b=fCBB61Rt6hMqTU6nIGe41gEylYKDHXK/YMjI3pSmX2PqPPBj+bWez5TiBWgDzo4gd
Yj393PvTKwabd5iN5ZQTSLYkAwbwqOqZowr61I5qgmrT+qd4c+C+4bmMK3m5NN2bR2
1e3d6/scTTawaqd1uUwSvQtd2WTWkIe9uoyBljpqJcAyGmPtS8c3eXdxl3hpV86XTa
+v0Gh1tB5mhLsN4uxJf79mxzWF09wewVERPxMaMMheVuaCkMQvUeqA1W3D7Qc2KGBq
zGh+56d+dtQplV4sxJ/rtzjnoX3HdSgdlVMOWH62sWtZXDDKfH9QQ1iAZGaq3xjMqP
bqG0Xp3BoGWOg==
In-Reply-To: <kdnlc4Fgl4fU1@mid.individual.net>
Feedback-ID: 75857154:user:proton
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
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: <https://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>
X-Mailman-Original-Message-ID: <SJXiQDnGka3VfQRZVMeoW3ssdKe3sT0t7qyh0dxS-LFrOQnT2qePsmq6em0P1cY1wwvPwEbCOTjGwEC5M-5UqC9BmnyFAW4JvwhiKgQ9gS0=@proton.me>
X-Mailman-Original-References: <0yjTTMo6f2sNAeHM8DWbLsJ3Yh3N1Fc-9MUmGXN4PoQ7rh3ovCCCEDrEb-UkCDWxIfwO1KaLP8WS2QMGtWz7phfJOU4rH-uhW5X8Wov-xEU=@proton.me>
<mailman.27.1685477273.23016.python-list@python.org>
<kdnlc4Fgl4fU1@mid.individual.net>
 by: James Schaffler - Wed, 31 May 2023 02:01 UTC

On Tuesday, May 30th, 2023 at 9:14 PM, Greg Ewing wrote:
> Globals you create by executing code in the REPL have their own
> namespace. But everything else is shared -- builtins, imported
> Python modules, imported C extension modules, etc. etc.

Thanks for the explanation. Could you elaborate on precisely how "everything else is shared"? As far as I understand, if you run the following code:

from code import InteractiveInterpreter
interp = InteractiveInterpreter()
import numpy as np
interp.runcode("np.__name__")

this will result in the error
Traceback (most recent call last):
File "<string>", line 1, in <module>
NameError: name 'np' is not defined

which seems to imply that imports in the parent shell are not shared with interpreters and vice versa (if you swap the places of the import and the __name__ call).

Thanks,
Jim

Re: Why does IDLE use a subprocess?

<mailman.37.1685499516.23016.python-list@python.org>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=23476&group=comp.lang.python#23476

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: rosuav@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Why does IDLE use a subprocess?
Date: Wed, 31 May 2023 12:18:23 +1000
Lines: 51
Message-ID: <mailman.37.1685499516.23016.python-list@python.org>
References: <0yjTTMo6f2sNAeHM8DWbLsJ3Yh3N1Fc-9MUmGXN4PoQ7rh3ovCCCEDrEb-UkCDWxIfwO1KaLP8WS2QMGtWz7phfJOU4rH-uhW5X8Wov-xEU=@proton.me>
<mailman.27.1685477273.23016.python-list@python.org>
<kdnlc4Fgl4fU1@mid.individual.net>
<SJXiQDnGka3VfQRZVMeoW3ssdKe3sT0t7qyh0dxS-LFrOQnT2qePsmq6em0P1cY1wwvPwEbCOTjGwEC5M-5UqC9BmnyFAW4JvwhiKgQ9gS0=@proton.me>
<CAPTjJmqEOzifYwoihsjbbFm36wf2TkhiiXiSezm5B1Nq=BnS4Q@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de Czyt+9GKQGUz5jVasKVCkgEWJvfyhae7ew9rU4WxYbuw==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=YDIniMci;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'traceback': 0.04; '(most':
0.05; 'last):': 0.05; '2023': 0.07; 'else.': 0.07; 'parent': 0.07;
'pep': 0.07; 'subject:Why': 0.07; 'namespace': 0.09; 'numpy':
0.09; 'subject:IDLE': 0.09; 'url-ip:151.101.0.223/32': 0.09; 'url-
ip:151.101.128.223/32': 0.09; 'url-ip:151.101.192.223/32': 0.09;
'url-ip:151.101.64.223/32': 0.09; 'import': 0.15; '(also,': 0.16;
'(note': 0.16; 'builtin': 0.16; 'chrisa': 0.16; 'cpython': 0.16;
'elaborate': 0.16; 'extensions,': 0.16; 'from:addr:rosuav': 0.16;
'from:name:chris angelico': 0.16; 'greg': 0.16; 'interpreter':
0.16; 'isolated': 0.16; 'modules,': 0.16; 'object,': 0.16;
'subject:does': 0.16; 'swap': 0.16; 'url:peps': 0.16; 'versa':
0.16; 'wrote:': 0.16; 'python': 0.16; 'pm,': 0.19; 'to:addr
:python-list': 0.20; 'code': 0.23; 'run': 0.23; 'actual': 0.25;
'extension': 0.25; 'seems': 0.26; 'object': 0.26; "isn't": 0.27;
'else': 0.27; 'coming': 0.27; '>>>': 0.28; 'error': 0.29; 'think':
0.32; '"",': 0.32; 'python-list': 0.32; 'message-
id:@mail.gmail.com': 0.32; 'but': 0.32; 'there': 0.33; 'same':
0.34; 'header:In-Reply-To:1': 0.34; 'received:google.com': 0.34;
'meaning': 0.35; 'following': 0.35; 'from:addr:gmail.com': 0.35;
'currently': 0.37; 'file': 0.38; 'could': 0.38; 'thanks': 0.38;
'single': 0.39; 'enough': 0.39; 'seeing': 0.39; 'shared': 0.39;
'wed,': 0.39; 'still': 0.40; 'above': 0.62; 'skip:i 20': 0.62;
'url-ip:151.101.0/24': 0.62; 'url-ip:151.101.128/24': 0.62; 'url-
ip:151.101.192/24': 0.62; 'url-ip:151.101.64/24': 0.62;
'internal': 0.63; 'true': 0.63; 'great': 0.63; 'everything': 0.63;
'representing': 0.64; 'james': 0.68; 'too.': 0.70; 'executing':
0.84; 'imports': 0.84; 'interpreters': 0.84; 'affect': 0.91;
'trick': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20221208; t=1685499514; x=1688091514;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:from:to:cc:subject:date:message-id:reply-to;
bh=Bpy389+qU0IIMuluO1qFWpk9BYmGsFFx5Y313FdLsuM=;
b=YDIniMcivhN3DbPYewOqcqiu0jU/xEdddA0wx8Dn0bxHVab9QyPU0GkExPkHWuoVB+
K+0UpwzxgB32VIf2zYEg9ZZopGYc1JG6mVuz7AHBHvXSStFPUEh442EHQxmKTzaKRw36
tD4N8wVOYTViuTyZd0NPhEMLtBk1qx6iGDqQCIVH0opwpx9gnX6c4scGx+P8emYQBUj5
9DGXx5t+QuA2AY2/wj+llOr0SIEjRo2NSBl/LxmhjqlLXQ2uq5X+Fuvjebzs4x+wvqbQ
esujvPj9dk8rwIKGq7cP3etTpjjzqYiRT0pnqKMBu5ZOpOa5w6C+97txjqDvcZ9d6PZT
yYYw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20221208; t=1685499514; x=1688091514;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=Bpy389+qU0IIMuluO1qFWpk9BYmGsFFx5Y313FdLsuM=;
b=Jear1CCu0Q+9WR1UUjQ8YQFw2jFjKFL5HrEIv1ChxHr107HKusZ1mddRI3GkKDIV/q
fRa6SO1RWx9q1k9xtyFRHUeteOrV7yGSREcyWnbLVUZ14nQJsfhoCWk5n3OWndOFZLnO
IyY+WiebDyaLCcRbC/E7mKlrk0nvCacgrdPPFLMvpKx5oKyyyFOCrya0Dg8VuOQJgoQM
0YzL4n4LR1AgHziq8oEqbnYD4KsJdK8apK2fnFZe57yflVf506Od1xS26iACqBGz6/Pv
dmtocqcwBicFUA8UXWUOYzCydZZ0/c4TQkvT3pw+lowjawIKNs6O3PmE1xA+psX8ohGZ
RWKQ==
X-Gm-Message-State: AC+VfDzeqISNzvTME9FCTihJqgdcB+0D4OVsRsXkKX57/a7AlZYjBGOd
niFF+/gcx2lb5OpaKY9Y9Z84KzRLVfpEpQUis43PqVexPSpqaQ==
X-Google-Smtp-Source: ACHHUZ55UiNil/Yvs9hojY+vAvDfefcQumBbcOBJUqnz0y1Ipk1z3z3mbT+MwYaajHIpbYwFfqHb6/bZwm7gCtU1uiI=
X-Received: by 2002:a17:907:7e93:b0:96f:bf78:c380 with SMTP id
qb19-20020a1709077e9300b0096fbf78c380mr4055747ejc.55.1685499514461; Tue, 30
May 2023 19:18:34 -0700 (PDT)
In-Reply-To: <SJXiQDnGka3VfQRZVMeoW3ssdKe3sT0t7qyh0dxS-LFrOQnT2qePsmq6em0P1cY1wwvPwEbCOTjGwEC5M-5UqC9BmnyFAW4JvwhiKgQ9gS0=@proton.me>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
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: <https://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>
X-Mailman-Original-Message-ID: <CAPTjJmqEOzifYwoihsjbbFm36wf2TkhiiXiSezm5B1Nq=BnS4Q@mail.gmail.com>
X-Mailman-Original-References: <0yjTTMo6f2sNAeHM8DWbLsJ3Yh3N1Fc-9MUmGXN4PoQ7rh3ovCCCEDrEb-UkCDWxIfwO1KaLP8WS2QMGtWz7phfJOU4rH-uhW5X8Wov-xEU=@proton.me>
<mailman.27.1685477273.23016.python-list@python.org>
<kdnlc4Fgl4fU1@mid.individual.net>
<SJXiQDnGka3VfQRZVMeoW3ssdKe3sT0t7qyh0dxS-LFrOQnT2qePsmq6em0P1cY1wwvPwEbCOTjGwEC5M-5UqC9BmnyFAW4JvwhiKgQ9gS0=@proton.me>
 by: Chris Angelico - Wed, 31 May 2023 02:18 UTC

On Wed, 31 May 2023 at 12:03, James Schaffler via Python-list
<python-list@python.org> wrote:
>
> On Tuesday, May 30th, 2023 at 9:14 PM, Greg Ewing wrote:
> > Globals you create by executing code in the REPL have their own
> > namespace. But everything else is shared -- builtins, imported
> > Python modules, imported C extension modules, etc. etc.
>
> Thanks for the explanation. Could you elaborate on precisely how "everything else is shared"? As far as I understand, if you run the following code:
>
> from code import InteractiveInterpreter
> interp = InteractiveInterpreter()
> import numpy as np
> interp.runcode("np.__name__")
>
> this will result in the error
> Traceback (most recent call last):
> File "<string>", line 1, in <module>
> NameError: name 'np' is not defined
>
> which seems to imply that imports in the parent shell are not shared with interpreters and vice versa (if you swap the places of the import and the __name__ call).
>

Yep, what you're seeing there is the namespace and nothing else. But
if you mess with an actual builtin object, it'll be changed for the
other interpreter too.

>>> import ctypes
>>> ctypes.cast(id(42), ctypes.POINTER(ctypes.c_int))[6] = 43
>>> 41+1
43
>>> from code import InteractiveInterpreter
>>> interp = InteractiveInterpreter()
>>> interp.runcode("print(41+1)")
43

(Note that this only works in CPython and only with integers small
enough to be in the cache, meaning that there is only one such object
representing that integer.)

The same is true of C extensions, which often have their own internal
state, and that state isn't isolated to a single interpreter.

Better isolation is coming with PEP 554
https://peps.python.org/pep-0554/ which also has some great
information about what currently is NOT isolated. (Also, even then,
some things won't be fully isolated; I think that the ctypes trick
above might still affect a subinterpreter even in a post-PEP554
world.)

ChrisA

Re: Why does IDLE use a subprocess?

<mailman.49.1685585772.23016.python-list@python.org>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=23491&group=comp.lang.python#23491

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: jschaffler@proton.me (James Schaffler)
Newsgroups: comp.lang.python
Subject: Re: Why does IDLE use a subprocess?
Date: Thu, 01 Jun 2023 02:08:56 +0000
Lines: 35
Message-ID: <mailman.49.1685585772.23016.python-list@python.org>
References: <0yjTTMo6f2sNAeHM8DWbLsJ3Yh3N1Fc-9MUmGXN4PoQ7rh3ovCCCEDrEb-UkCDWxIfwO1KaLP8WS2QMGtWz7phfJOU4rH-uhW5X8Wov-xEU=@proton.me>
<mailman.27.1685477273.23016.python-list@python.org>
<kdnlc4Fgl4fU1@mid.individual.net>
<SJXiQDnGka3VfQRZVMeoW3ssdKe3sT0t7qyh0dxS-LFrOQnT2qePsmq6em0P1cY1wwvPwEbCOTjGwEC5M-5UqC9BmnyFAW4JvwhiKgQ9gS0=@proton.me>
<CAPTjJmqEOzifYwoihsjbbFm36wf2TkhiiXiSezm5B1Nq=BnS4Q@mail.gmail.com>
<SiKzQ57Lv4uGS1bluhHj2wpau_ynFO6GDt3Ww6hinsWBZ4m98jLMiMy8pmdriPc7_lI7esmbLWNhApJVI37aVv58CMABnFyCIUyQwDcbfJ8=@proton.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de R7ySPdacMuleJ/8xuE0EegoOs7nUW7rHT2uJcyIFIMVQ==
Return-Path: <jschaffler@proton.me>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=proton.me header.i=@proton.me header.b=M3j5flan;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '2023': 0.07; 'else.':
0.07; 'pep': 0.07; 'subject:Why': 0.07; 'angelico': 0.09; 'cc:addr
:python-list': 0.09; 'namespace': 0.09; 'responses': 0.09;
'subject:IDLE': 0.09; 'url-ip:151.101.0.223/32': 0.09; 'url-
ip:151.101.128.223/32': 0.09; 'url-ip:151.101.192.223/32': 0.09;
'url-ip:151.101.64.223/32': 0.09; 'cc:no real name:2**0': 0.14;
'import': 0.15; '(also,': 0.16; '(note': 0.16; 'builtin': 0.16;
'cpython': 0.16; 'extensions,': 0.16; 'interpreter': 0.16;
'isolated': 0.16; 'object,': 0.16; 'received:185.70.41': 0.16;
'received:185.70.41.104': 0.16;
'received:mail-41104.protonmail.ch': 0.16; 'subject:does': 0.16;
'url:peps': 0.16; 'wrote:': 0.16; 'pm,': 0.19;
'cc:addr:python.org': 0.20; 'code': 0.23; 'actual': 0.25;
'cc:2**0': 0.25; 'object': 0.26; 'received:185.70': 0.26;
'received:protonmail.ch': 0.26; "isn't": 0.27; 'coming': 0.27;
'chris': 0.28; 'think': 0.32; 'everyone': 0.32; 'but': 0.32;
'there': 0.33; 'same': 0.34; 'header:In-Reply-To:1': 0.34;
'meaning': 0.35; 'received:ch': 0.35; 'currently': 0.37; 'single':
0.39; 'enough': 0.39; 'seeing': 0.39; 'still': 0.40; 'above':
0.62; 'skip:i 20': 0.62; 'url-ip:151.101.0/24': 0.62; 'url-
ip:151.101.128/24': 0.62; 'url-ip:151.101.192/24': 0.62; 'url-
ip:151.101.64/24': 0.62; 'internal': 0.63; 'true': 0.63; 'great':
0.63; 'representing': 0.64; 'amazing': 0.65; 'too.': 0.70;
'received:185': 0.71; 'header:Received:2': 0.84; 'affect': 0.91;
'trick': 0.91
Authentication-Results: mail-41104.protonmail.ch;
dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me
header.b="M3j5flan"
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me;
s=protonmail; t=1685585358; x=1685844558;
bh=SCZ022ipemu6EmfRdGkHwi8kClh7OncKiww+b9XH+rA=;
h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References:
Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID:
Message-ID:BIMI-Selector;
b=M3j5flanyGwYx8vuOxvfGxZqyIknOg+EBMHAK3WVEw1g4RJRXjzLrLpvUMuUvAIF1
K0eIpTTi8HhlyWstz7DzD0uZJ8PGV4ug4KgjgqAiYC0L7vW/uRw3i3sVqJJzX+RTLR
0MZ7xQJBoH9rYMlUh0WPowzdyEvDliutq7xW/QKy8Ggx+Lmc4hlrgcVBxit37tQhOu
8bmhx6MneepAxxYRM7iuC1fxcrYfpVK8Mz5/jeZ1ZQJxGR1SsVQ8Fa3LC7jyrO/ckJ
f+qUW9gFMuzzcDHtKOqd2TgQatKPJen4YYMd+3mNhmxFR2qvalGeOM4XW2ZzheAc2s
i45oCh9fesh2g==
In-Reply-To: <CAPTjJmqEOzifYwoihsjbbFm36wf2TkhiiXiSezm5B1Nq=BnS4Q@mail.gmail.com>
Feedback-ID: 75857154:user:proton
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
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: <https://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>
X-Mailman-Original-Message-ID: <SiKzQ57Lv4uGS1bluhHj2wpau_ynFO6GDt3Ww6hinsWBZ4m98jLMiMy8pmdriPc7_lI7esmbLWNhApJVI37aVv58CMABnFyCIUyQwDcbfJ8=@proton.me>
X-Mailman-Original-References: <0yjTTMo6f2sNAeHM8DWbLsJ3Yh3N1Fc-9MUmGXN4PoQ7rh3ovCCCEDrEb-UkCDWxIfwO1KaLP8WS2QMGtWz7phfJOU4rH-uhW5X8Wov-xEU=@proton.me>
<mailman.27.1685477273.23016.python-list@python.org>
<kdnlc4Fgl4fU1@mid.individual.net>
<SJXiQDnGka3VfQRZVMeoW3ssdKe3sT0t7qyh0dxS-LFrOQnT2qePsmq6em0P1cY1wwvPwEbCOTjGwEC5M-5UqC9BmnyFAW4JvwhiKgQ9gS0=@proton.me>
<CAPTjJmqEOzifYwoihsjbbFm36wf2TkhiiXiSezm5B1Nq=BnS4Q@mail.gmail.com>
 by: James Schaffler - Thu, 1 Jun 2023 02:08 UTC

On Tuesday, May 30th, 2023 at 10:18 PM, Chris Angelico wrote:
> Yep, what you're seeing there is the namespace and nothing else. But
> if you mess with an actual builtin object, it'll be changed for the
> other interpreter too.
>
> > > > import ctypes
> > > > ctypes.cast(id(42), ctypes.POINTER(ctypes.c_int))[6] = 43
> > > > 41+1
>
> 43
>
> > > > from code import InteractiveInterpreter
> > > > interp = InteractiveInterpreter()
> > > > interp.runcode("print(41+1)")
>
> 43
>
> (Note that this only works in CPython and only with integers small
> enough to be in the cache, meaning that there is only one such object
> representing that integer.)
>
> The same is true of C extensions, which often have their own internal
> state, and that state isn't isolated to a single interpreter.
>
> Better isolation is coming with PEP 554
> https://peps.python.org/pep-0554/ which also has some great
> information about what currently is NOT isolated. (Also, even then,
> some things won't be fully isolated; I think that the ctypes trick
> above might still affect a subinterpreter even in a post-PEP554
> world.)

Amazing example! Thank you everyone for the detailed responses - will be sure to check out the PEP as well.

Jim


devel / comp.lang.python / Why does IDLE use a subprocess?

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor