@@ -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".
0 commit comments