-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
PEP 797: Shared Object Proxies for Subinterpreters #4536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Abstract | ||
======== | ||
|
||
This PEP introduces a new :func:`~concurrent.interpreters.share` function to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PEP introduces a new :func:`~concurrent.interpreters.share` function to | |
This PEP introduces a new :func:`!share` function to |
|
||
This PEP introduces a new :func:`~concurrent.interpreters.share` function to | ||
the :mod:`concurrent.interpreters` module, which allows *any* arbitrary object | ||
to be shared for a period of time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shared between what? Processes, threads, interpreters, over the network, etc?
|
||
from concurrent import interpreters | ||
|
||
with open("spanish_inquisition.txt") as unshareable: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
always use an encoding!
with open("spanish_inquisition.txt") as unshareable: | |
with open('spanish_inquisition.txt', encoding='utf-8') as unshareable: |
create multiple interpreters in a single Python process. This works well for | ||
stateless code (that is, code that doesn't need any state from a caller) and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create multiple interpreters in a single Python process. This works well for | |
stateless code (that is, code that doesn't need any state from a caller) and | |
create multiple interpreters in a single Python process. This works well for | |
code that doesn't need any state from a caller ('stateless code') and |
create multiple interpreters in a single Python process. This works well for | ||
stateless code (that is, code that doesn't need any state from a caller) and | ||
objects that can be serialized, but it is fairly common for applications to | ||
want to use highly-complex data structures (that cannot be serialized) with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I would use fewer paranthetical asides, though this is style. Here, I don't think the comment about serialisation adds much, it's clear from context we're talking about non-serialisable data (or even data that could be serialised but that is too expensive to do so)
want to use highly-complex data structures (that cannot be serialized) with | |
require highly-complex data structures with |
In order to implement the immortality mechanism used by shared object proxies, | ||
several assumptions had to be made about the object lifecycle in the C API. | ||
So, some best practices in the C API (such as using the object allocator for | ||
objects) are made harder requirements by the implementation of this PEP. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be explicit about what those assumptions are. In general, it is hard to make assumptions about what code in the wild is or is not doing (Hyrum's Law etc)
The author of this PEP believes it is unlikely that this will cause breakage, | ||
as he has not ever seen code in the wild that violates the assumptions made | ||
about the object lifecycle as required by the reference implementation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are millions of lines of proprietary code that you & I haven't seen ;-)
More generally just re-emphasising the point on explicitly enumerating the changes in semantics that you propose.
which prevents any concurrent modification to their reference count. | ||
This can cause them to take up very large amounts of memory if mismanaged. | ||
|
||
The :func:`~concurrent.interpreters.share` context manager does its best |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The :func:`~concurrent.interpreters.share` context manager does its best | |
The :func:`!share` context manager does its best |
The largest issue with shared object proxies is that in order to have | ||
thread-safe reference counting operations, they must be :term:`immortal`, | ||
which prevents any concurrent modification to their reference count. | ||
This can cause them to take up very large amounts of memory if mismanaged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Large amounts of memory -> denial of service attack, which is the actual security concern here
usage (due to :term:`immortality <immortal>`, which will be discussed more | ||
later). As such, this PEP does not make other mechanisms for sharing objects |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which part/section are you referring to here?
Basic requirements (all PEP Types)
pep-NNNN.rst
), PR title (PEP 123: <Title of PEP>
) andPEP
headerAuthor
orSponsor
, and formally confirmed their approvalAuthor
,Status
(Draft
),Type
andCreated
headers filled out correctlyPEP-Delegate
,Topic
,Requires
andReplaces
headers completed if appropriate.github/CODEOWNERS
for the PEPStandards Track requirements
Python-Version
set to valid (pre-beta) future Python version, if relevantDiscussions-To
andPost-History
📚 Documentation preview 📚: https://pep-previews--4536.org.readthedocs.build/pep-0797/