Skip to content

Commit 81d9734

Browse files
PEP 734: Minor Updates (#3741)
* Expand the InterpreterPoolExecutor section. * Identify the rest of the exception types. * Add a note about "external" interpreters. * Add Interpreter.close(). * Add a note about queued objects whose interpreter is destroyed.
1 parent e9a6048 commit 81d9734

File tree

1 file changed

+63
-9
lines changed

1 file changed

+63
-9
lines changed

peps/pep-0734.rst

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,16 @@ An ``interpreters.Interpreter`` object that represents the interpreter
319319
There will only be one object for any given interpreter.
320320

321321
If the interpreter was created with ``interpreters.create()`` then
322-
it will be destroyed as soon as all ``Interpreter`` objects have been
323-
deleted.
322+
it will be destroyed as soon as all ``Interpreter`` objects with its ID
323+
(across all interpreters) have been deleted.
324+
325+
``Interpreter`` objects may represent other interpreters than those
326+
created by ``interpreters.create()``. Examples include the main
327+
interpreter (created by Python's runtime initialization) and those
328+
created via the C-API, using ``Py_NewInterpreter()``. Such
329+
``Interpreter`` objects will not be able to interact with their
330+
corresponding interpreters, e.g. via ``Interpreter.exec()``
331+
(though we may relax this in the future).
324332

325333
Attributes and methods:
326334

@@ -421,6 +429,9 @@ Attributes and methods:
421429
t = threading.Thread(target=task)
422430
t.start()
423431

432+
* ``close()``
433+
Destroy the underlying interpreter.
434+
424435
Communicating Between Interpreters
425436
----------------------------------
426437

@@ -520,6 +531,13 @@ Attributes and methods:
520531
If "syncobj" is None (the default) then the queue's default
521532
value is used.
522533

534+
If an object is still in the queue, and the interpreter which put
535+
it in the queue (i.e. to which it belongs) is destroyed, then the
536+
object is immediately removed from the queue. (We may later add
537+
an option to replace the removed object in the queue with a
538+
sentinel or to raise an exception for the corresponding ``get()``
539+
call.)
540+
523541
* ``put_nowait(obj, *, syncobj=None)``
524542
Like ``put()`` but effectively with an immediate timeout.
525543
Thus if the queue is full, it immediately raises
@@ -662,6 +680,17 @@ pass an object around to indicate who can use the resource::
662680
Exceptions
663681
----------
664682

683+
* ``InterpreterError``
684+
Indicates that some interpreter-related failure occurred.
685+
686+
This exception is a subclass of ``Exception``.
687+
688+
* ``InterpreterNotFoundError``
689+
Raised from ``Interpreter`` methods after the underlying
690+
interpreter has been destroyed, e.g. via the C-API.
691+
692+
This exception is a subclass of ``InterpreterError``.
693+
665694
* ``ExecutionFailed``
666695
Raised from ``Interpreter.exec()`` and ``Interpreter.call()``
667696
when there's an uncaught exception.
@@ -677,28 +706,53 @@ Exceptions
677706
* ``snapshot`` - a ``traceback.TracebackException`` object
678707
for the original exception
679708

680-
This exception is a subclass of ``RuntimeError``.
709+
This exception is a subclass of ``InterpreterError``.
710+
711+
* ``QueueError``
712+
Indicates that some queue-related failure occurred.
713+
714+
This exception is a subclass of ``Exception``.
715+
716+
* ``QueueNotFoundError``
717+
Raised from ``interpreters.Queue`` methods after the underlying
718+
queue has been destroyed.
719+
720+
This exception is a subclass of ``QueueError``.
681721

682722
* ``QueueEmpty``
683723
Raised from ``Queue.get()`` (or ``get_nowait()`` with no default)
684724
when the queue is empty.
685725

686-
This exception is a subclass of ``queue.Empty``.
726+
This exception is a subclass of both ``QueueError``
727+
and the stdlib ``queue.Empty``.
687728

688729
* ``QueueFull``
689730
Raised from ``Queue.put()`` (with a timeout) or ``put_nowait()``
690731
when the queue is already at its max size.
691732

692-
This exception is a subclass of ``queue.Full``.
733+
This exception is a subclass of both ``QueueError``
734+
and the stdlib ``queue.Empty``.
693735

694736
InterpreterPoolExecutor
695737
-----------------------
696738

697739
Along with the new ``interpreters`` module, there will be a new
698-
``concurrent.futures.InterpreterPoolExecutor``. Each worker executes
699-
in its own thread with its own subinterpreter. Communication may
700-
still be done through ``interpreters.Queue`` objects,
701-
set with the initializer.
740+
``concurrent.futures.InterpreterPoolExecutor``. It will be a
741+
derivative of ``ThreadPoolExecutor``, where each worker executes
742+
in its own thread, but each with its own subinterpreter.
743+
744+
Like the other executors, ``InterpreterPoolExecutor`` will support
745+
callables for tasks, and for the initializer. Also like the other
746+
executors, the arguments in both cases will be mostly unrestricted.
747+
The callables and arguments will typically be serialized when sent
748+
to a worker's interpreter, e.g. with pickle, like how the
749+
``ProcessPoolExecutor`` works. This contrasts with
750+
``Interpreter.call()``, which will (at least initially)
751+
be much more restricted.
752+
753+
Communication between workers, or between the executor
754+
(or generally its interpreter) and the workers, may still be done
755+
through ``interpreters.Queue`` objects, set with the initializer.
702756

703757
sys.implementation.supports_isolated_interpreters
704758
-------------------------------------------------

0 commit comments

Comments
 (0)