Skip to content

Commit fe86353

Browse files
Fix formatting and typos.
1 parent 0a5d0e4 commit fe86353

File tree

2 files changed

+106
-70
lines changed

2 files changed

+106
-70
lines changed

Doc/library/interpreters.rst

Lines changed: 105 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -51,70 +51,112 @@ to keep in mind about using multiple interpreters:
5151
.. XXX Are there other relevant details to list?
5252
5353
54-
API Summary
55-
-----------
54+
Reference
55+
---------
56+
57+
This module defines the following functions:
58+
59+
.. function:: list_all()
60+
61+
-> [Interpreter]``
62+
Get all existing interpreters.
63+
64+
.. function:: get_current()
65+
66+
-> Interpreter
67+
Get the currently running interpreter.
68+
69+
.. function:: get_main()
70+
71+
-> Interpreter
72+
Get the main interpreter.
73+
74+
.. function:: create()
75+
76+
-> Interpreter
77+
Initialize a new (idle) Python interpreter.
78+
79+
80+
Interpreter objects
81+
^^^^^^^^^^^^^^^^^^^
82+
83+
.. class:: Interpreter(id)
84+
85+
A single interpreter in the current process.
86+
87+
Generally, :class:`Interpreter` shouldn't be called directly.
88+
Instead, use :func:`create` or one of the other module functions.
89+
90+
.. attribute:: id
91+
92+
(read-only)
93+
94+
The interpreter's ID.
95+
96+
.. attribute:: whence
97+
98+
(read-only)
99+
100+
Where the interpreter came from.
101+
102+
.. method:: is_running()
103+
104+
Is the interpreter currently executing code in its
105+
:mod:`!__main__` module?
106+
107+
.. method:: close()
108+
109+
Finalize and destroy the interpreter.
110+
111+
.. method:: prepare_main(ns=None, **kwargs)
112+
113+
Bind "shareable" objects in the interpreter's
114+
:mod:`!__main__` module.
115+
116+
.. method:: exec(code, /, dedent=True)
117+
118+
Run the given source code in the interpreter (in the current thread).
119+
120+
.. method:: call(callable, /, *args, **kwargs)
121+
122+
Run the given function in the interpreter (in the current thread).
123+
124+
.. method:: call_in_thread(callable, /, *args, **kwargs)
125+
126+
Run the given function in the interpreter (in a new thread).
127+
128+
Exceptions
129+
^^^^^^^^^^
130+
131+
.. exception:: InterpreterError
132+
133+
This exception, a subclass of :exc:`Exception`, is raised when
134+
an interpreter-related error happens.
135+
136+
.. exception:: InterpreterNotFoundError
137+
138+
This exception, a subclass of :exc:`InterpreterError`, is raised when
139+
the targeted interpreter no longer exists.
140+
141+
.. exception:: ExecutionFailed
142+
143+
This exception, a subclass of :exc:`InterpreterError`, is raised when
144+
the running code raised an uncaught exception.
145+
146+
.. attribute:: excinfo
147+
148+
A basic snapshot of the exception raised in the other interpreter.
149+
150+
.. XXX Document the excinfoattrs?
151+
152+
.. exception:: NotShareableError
153+
154+
This exception, a subclass of :exc:`TypeError`, is raised when
155+
an object cannot be sent to another interpreter.
156+
157+
158+
.. XXX Add functions for communicating between interpreters.
56159
57-
+----------------------------------+----------------------------------------------+
58-
| signature | description |
59-
+==================================+==============================================+
60-
| ``list_all() -> [Interpreter]`` | Get all existing interpreters. |
61-
+----------------------------------+----------------------------------------------+
62-
| ``get_current() -> Interpreter`` | Get the currently running interpreter. |
63-
+----------------------------------+----------------------------------------------+
64-
| ``get_main() -> Interpreter`` | Get the main interpreter. |
65-
+----------------------------------+----------------------------------------------+
66-
| ``create() -> Interpreter`` | Initialize a new (idle) Python interpreter. |
67-
+----------------------------------+----------------------------------------------+
68-
69-
|
70-
71-
+---------------------------------------------------+---------------------------------------------------+
72-
| signature | description |
73-
+===================================================+===================================================+
74-
| ``class Interpreter`` | A single interpreter. |
75-
+---------------------------------------------------+---------------------------------------------------+
76-
| ``.id`` | The interpreter's ID (read-only). |
77-
+---------------------------------------------------+---------------------------------------------------+
78-
| ``.whence`` | Where the interpreter came from (read-only). |
79-
+---------------------------------------------------+---------------------------------------------------+
80-
| ``.is_running() -> bool`` | Is the interpreter currently executing code |
81-
| | in its :mod:`!__main__` module? |
82-
+---------------------------------------------------+---------------------------------------------------+
83-
| ``.close()`` | Finalize and destroy the interpreter. |
84-
+---------------------------------------------------+---------------------------------------------------+
85-
| ``.prepare_main(ns=None, **kwargs)`` | Bind "shareable" objects in :mod:`!__main__`. |
86-
+---------------------------------------------------+---------------------------------------------------+
87-
| ``.exec(src_str, /, dedent=True)`` | | Run the given source code in the interpreter |
88-
| | | (in the current thread). |
89-
+---------------------------------------------------+---------------------------------------------------+
90-
| ``.call(callable, /, *args, **kwargs)`` | | Run the given function in the interpreter |
91-
| | | (in the current thread). |
92-
+---------------------------------------------------+---------------------------------------------------+
93-
| ``.call_in_thread(callable, /, *args, **kwargs)`` | | Run the given function in the interpreter |
94-
| | | (in a new thread). |
95-
+---------------------------------------------------+---------------------------------------------------+
96-
97-
Exceptions:
98-
99-
+--------------------------+------------------+---------------------------------------------------+
100-
| class | base class | description |
101-
+==========================+==================+===================================================+
102-
| InterpreterError | Exception | An interpreter-related error happened. |
103-
+--------------------------+------------------+---------------------------------------------------+
104-
| InterpreterNotFoundError | InterpreterError | The targeted interpreter no longer exists. |
105-
+--------------------------+------------------+---------------------------------------------------+
106-
| ExecutionFailed | InterpreterError | The running code raised an uncaught exception. |
107-
+--------------------------+------------------+---------------------------------------------------+
108-
| NotShareableError | TypeError | The object cannot be sent to another interpreter. |
109-
+--------------------------+------------------+---------------------------------------------------+
110-
111-
.. XXX Document the ExecutionFailed attrs.
112-
113-
114-
.. XXX Add API summary for communicating between interpreters.
115-
116-
117-
.. _interp-examples:
118160
119161
Basic Usage
120162
-----------
@@ -151,10 +193,4 @@ Creating an interpreter and running code in it:
151193
t.join()
152194

153195

154-
.. XXX Describe module functions in more detail.
155-
156-
157-
.. XXX Describe module types in more detail.
158-
159-
160196
.. XXX Explain about object "sharing".

Doc/whatsnew/3.14.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ for Python that were limited by the :term:`GIL`.
163163
Using multiple interpreters is similar in many ways to
164164
:mod:`multiprocessing`, in that they both provide isolated logical
165165
"processes" that can run in parallel, with no sharing by default.
166-
. However, when using multiple interpreters, an application will use
166+
However, when using multiple interpreters, an application will use
167167
fewer system resources and will operate more efficiently (since it
168168
stays within the same process). Think of multiple interpreters as
169169
having the isolation of processes with the efficiency of threads.

0 commit comments

Comments
 (0)