-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-76785: Multiple Interpreters in the Stdlib (PEP 554) #18817
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
Changes from 1 commit
f5b464a
331be62
3f2f2f4
4618343
ec63183
80f6808
724e618
abd0011
d502415
a751e15
56083c2
14e97fc
9ab54eb
b7dce73
e9b56b8
2bf89d4
158e54f
9e2f9d6
2e608fb
71ad4d7
b12e3d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,7 +8,7 @@ | |||||||
|
|
||||||||
| -------------- | ||||||||
|
|
||||||||
| This module provides highlevel tools for working with sub-interpreters, | ||||||||
| This module provides highlevel tools for working with sub-interpreters, | ||||||||
|
nanjekyejoannah marked this conversation as resolved.
Outdated
|
||||||||
| such as creating them, running code in them, or sending data between them. | ||||||||
| It is a wrapper around the low-level :mod:`_interpreters` module. | ||||||||
|
nanjekyejoannah marked this conversation as resolved.
Outdated
|
||||||||
|
|
||||||||
|
|
@@ -25,16 +25,18 @@ The Interpreter object represents a single interpreter. | |||||||
| .. method:: is_running() | ||||||||
|
|
||||||||
| Return whether or not the identified interpreter is running. | ||||||||
| It returns `True` and `False` otherwise. | ||||||||
|
Comment on lines
+25
to
+28
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO, this could be better phrased as: For comparison, see https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.is_running or https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.Future.cancelled. |
||||||||
|
|
||||||||
| .. method:: destroy() | ||||||||
|
|
||||||||
| Destroy the identified interpreter. Attempting to destroy the current | ||||||||
| interpreter results in a RuntimeError. So does an unrecognized ID. | ||||||||
| Destroy the interpreter. Attempting to destroy the current | ||||||||
| interpreter results in a `RuntimeError`. | ||||||||
|
Comment on lines
+30
to
+33
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC, it also results in a |
||||||||
|
|
||||||||
| .. method:: run(self, src_str, /, *, channels=None): | ||||||||
|
|
||||||||
| Run the given source code in the interpreter. This blocks the current | ||||||||
| thread until done. | ||||||||
| Run the given source code in the interpreter. This blocks | ||||||||
| the current thread until done. `channels` should be in | ||||||||
| the form : `(RecvChannel, SendChannel)`. | ||||||||
|
|
||||||||
| RecvChannel Objects | ||||||||
| ------------------- | ||||||||
|
|
@@ -47,68 +49,78 @@ The RecvChannel object represents a recieving channel. | |||||||
|
|
||||||||
| .. method:: recv() | ||||||||
|
|
||||||||
| Get the next object from the channel, and wait if none have been | ||||||||
| sent. Associate the interpreter with the channel. | ||||||||
| Get the next object from the channel, and wait if | ||||||||
| none have been sent. Associate the interpreter | ||||||||
| with the channel. | ||||||||
|
|
||||||||
| .. method:: recv_nowait(default=None) | ||||||||
|
|
||||||||
| Like ``recv()``, but return the default instead of waiting. | ||||||||
| Like ``recv()``, but return the default result | ||||||||
| instead of waiting. | ||||||||
|
|
||||||||
| .. method:: release() | ||||||||
| .. method:: release() | ||||||||
|
|
||||||||
| Close the channel for the current interpreter. 'send' and 'recv' (bool) may | ||||||||
| be used to indicate the ends to close. By default both ends are closed. | ||||||||
| Closing an already closed end is a noop. | ||||||||
| Release the channel for the current interpreter. | ||||||||
| By default both ends are released. Releasing an already | ||||||||
| released end results in a ``ChannelReleasedError`` exception. | ||||||||
|
Comment on lines
+61
to
+65
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO, the second sentence could be better phrased as: (Also added a Sphinx role, which should generate an inline link to the exception definition below) |
||||||||
|
|
||||||||
| .. method:: close(force=False) | ||||||||
|
|
||||||||
| Close the channel in all interpreters. | ||||||||
| Close the channel in all interpreters. By default | ||||||||
| both ends are closed. closing an already closed end | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| results in a ``ChannelClosedError`` exception. Without | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| seeting ``force`` to ``True`` a ``ChannelNotEmptyError`` | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Grammar fix and changed parameter name to use italics instead of backticks. Also adds sphinx role.
Suggested change
|
||||||||
| will be returned when a channel with data is closed. | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
|
|
||||||||
| SendChannel Objects | ||||||||
| -------------------- | ||||||||
|
|
||||||||
| The SendChannel object represents a sending channel. | ||||||||
| The ``SendChannel`` object represents a sending channel. | ||||||||
|
|
||||||||
| .. class:: SendChannel(id) | ||||||||
|
|
||||||||
| This class represents the receiving end of a channel. | ||||||||
| This class represents the sending end of a channel. | ||||||||
|
|
||||||||
| .. method:: send(obj) | ||||||||
|
|
||||||||
| Send the object (i.e. its data) to the receiving end of the channel | ||||||||
| and wait.Associate the interpreter with the channel. | ||||||||
| Send the object ``obj`` to the receiving end of the channel | ||||||||
| and wait. Associate the interpreter with the channel. | ||||||||
|
|
||||||||
| .. method:: send_nowait(obj) | ||||||||
|
|
||||||||
| Like ``send()``, but return False if not received. | ||||||||
| Like ``send()`` but return ``False`` if not received. | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Phrasing suggestion and clarification:
Suggested change
|
||||||||
|
|
||||||||
| .. method:: send_buffer(obj) | ||||||||
|
|
||||||||
| Send the object's buffer to the receiving end of the channel and wait. | ||||||||
| Associate the interpreter with the channel. | ||||||||
| Send the object's buffer to the receiving end of the | ||||||||
| channel and wait. Associate the interpreter with the | ||||||||
| channel. | ||||||||
|
|
||||||||
| .. method:: send_buffer_nowait(obj) | ||||||||
|
|
||||||||
| Like ``send_buffer()``, but return False if not received. | ||||||||
| Like ``send_buffer()`` but return ``False`` if not received. | ||||||||
|
Comment on lines
+100
to
+102
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my above comment on |
||||||||
|
|
||||||||
| .. method:: release() | ||||||||
|
|
||||||||
| Close the channel for the current interpreter. 'send' and 'recv' (bool) may | ||||||||
| be used to indicate the ends to close. By default both ends are closed. | ||||||||
| Closing an already closed end is a noop. | ||||||||
| Release the channel for the current interpreter. | ||||||||
| By default both ends are released. Releasing an already | ||||||||
| released end results in a ``ChannelReleasedError`` exception. | ||||||||
|
nanjekyejoannah marked this conversation as resolved.
|
||||||||
|
|
||||||||
| .. method:: close(force=False) | ||||||||
|
|
||||||||
| Close the channel in all interpreters. | ||||||||
| Close the channel in all interpreters. By default | ||||||||
| both ends are closed. closing an already closed end | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| results in a ``ChannelClosedError`` exception. | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
|
|
||||||||
| This module defines the following global functions: | ||||||||
|
|
||||||||
|
|
||||||||
| .. function:: is_shareable(obj) | ||||||||
|
|
||||||||
| Return `True` if the object's data can be shared between interpreters. | ||||||||
| Return ``True`` if the object's data can be shared between | ||||||||
| interpreters. | ||||||||
|
|
||||||||
| .. function:: create_channel() | ||||||||
|
|
||||||||
|
|
@@ -120,16 +132,18 @@ This module defines the following global functions: | |||||||
|
|
||||||||
| .. function:: create() | ||||||||
|
|
||||||||
| Initialize a new (idle) Python interpreter. | ||||||||
| Initialize a new (idle) Python interpreter. Get the currently | ||||||||
| running interpreter. This method returns an ``Interpreter`` object. | ||||||||
|
Comment on lines
+133
to
+136
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was "Get the currently running interpreter" accidentally included here? |
||||||||
|
|
||||||||
| .. function:: get_current() | ||||||||
|
|
||||||||
| Get the currently running interpreter. This method returns | ||||||||
| an `interpreter` object. | ||||||||
| an ``Interpreter`` object. | ||||||||
|
|
||||||||
| .. function:: list_all() | ||||||||
|
|
||||||||
| Get all existing interpreters. | ||||||||
| Get all existing interpreters. Returns a list | ||||||||
| of ``Interpreter`` objects. | ||||||||
|
|
||||||||
| This module also defines the following exceptions. | ||||||||
|
|
||||||||
|
|
@@ -140,35 +154,35 @@ This module also defines the following exceptions. | |||||||
|
|
||||||||
| .. exception:: ChannelError | ||||||||
|
|
||||||||
| This exception, a subclass of :exc:`Exception`, and is the base class for | ||||||||
| channel-related exceptions. | ||||||||
| This exception is a subclass of :exc:`Exception`, and is the base | ||||||||
| class for all channel-related exceptions. | ||||||||
|
|
||||||||
| .. exception:: ChannelNotFoundError | ||||||||
|
|
||||||||
| This exception, a subclass of :exc:`ChannelError`, is raised when the | ||||||||
| the identified channel was not found. | ||||||||
| This exception is a subclass of :exc:`ChannelError`, and is raised | ||||||||
| when the the identified channel is not found. | ||||||||
|
|
||||||||
| .. exception:: ChannelEmptyError | ||||||||
|
|
||||||||
| This exception, a subclass of :exc:`ChannelError`, is raised when | ||||||||
| This exception is a subclass of :exc:`ChannelError`, and is raised when | ||||||||
| the channel is unexpectedly empty. | ||||||||
|
|
||||||||
| .. exception:: ChannelNotEmptyError | ||||||||
|
|
||||||||
| This exception, a subclass of :exc:`ChannelError`, is raised when | ||||||||
| This exception is a subclass of :exc:`ChannelError`, and is raised when | ||||||||
| the channel is unexpectedly not empty. | ||||||||
|
|
||||||||
| .. exception:: NotReceivedError | ||||||||
|
|
||||||||
| This exception, a subclass of :exc:`ChannelError`, is raised when | ||||||||
| This exception is a subclass of :exc:`ChannelError`, and is raised when | ||||||||
| nothing was waiting to receive a sent object. | ||||||||
|
|
||||||||
| .. exception:: ChannelClosedError | ||||||||
|
|
||||||||
| This exception, a subclass of :exc:`ChannelError`, is raised when | ||||||||
| This exception is a subclass of :exc:`ChannelError`, and is raised when | ||||||||
| the channel is closed. | ||||||||
|
|
||||||||
| .. exception:: ChannelReleasedError | ||||||||
|
|
||||||||
| This exception, a subclass of :exc:`ChannelClosedError`, is raised when | ||||||||
| the channel is released (but not yet closed). | ||||||||
| This exception is a subclass of :exc:`ChannelClosedError`, and is raised | ||||||||
| when the channel is released (but not yet closed). | ||||||||
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.
Is the module going to be provisional still in 3.9 or is this going to be part of the stable API? If it's going to be provisional, I think it could include a note in the header to explain that.