@@ -319,8 +319,16 @@ An ``interpreters.Interpreter`` object that represents the interpreter
319
319
There will only be one object for any given interpreter.
320
320
321
321
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).
324
332
325
333
Attributes and methods:
326
334
@@ -421,6 +429,9 @@ Attributes and methods:
421
429
t = threading.Thread(target=task)
422
430
t.start()
423
431
432
+ * ``close() ``
433
+ Destroy the underlying interpreter.
434
+
424
435
Communicating Between Interpreters
425
436
----------------------------------
426
437
@@ -520,6 +531,13 @@ Attributes and methods:
520
531
If "syncobj" is None (the default) then the queue's default
521
532
value is used.
522
533
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
+
523
541
* ``put_nowait(obj, *, syncobj=None) ``
524
542
Like ``put() `` but effectively with an immediate timeout.
525
543
Thus if the queue is full, it immediately raises
@@ -662,6 +680,17 @@ pass an object around to indicate who can use the resource::
662
680
Exceptions
663
681
----------
664
682
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
+
665
694
* ``ExecutionFailed ``
666
695
Raised from ``Interpreter.exec() `` and ``Interpreter.call() ``
667
696
when there's an uncaught exception.
@@ -677,28 +706,53 @@ Exceptions
677
706
* ``snapshot `` - a ``traceback.TracebackException `` object
678
707
for the original exception
679
708
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 ``.
681
721
682
722
* ``QueueEmpty ``
683
723
Raised from ``Queue.get() `` (or ``get_nowait() `` with no default)
684
724
when the queue is empty.
685
725
686
- This exception is a subclass of ``queue.Empty ``.
726
+ This exception is a subclass of both ``QueueError ``
727
+ and the stdlib ``queue.Empty ``.
687
728
688
729
* ``QueueFull ``
689
730
Raised from ``Queue.put() `` (with a timeout) or ``put_nowait() ``
690
731
when the queue is already at its max size.
691
732
692
- This exception is a subclass of ``queue.Full ``.
733
+ This exception is a subclass of both ``QueueError ``
734
+ and the stdlib ``queue.Empty ``.
693
735
694
736
InterpreterPoolExecutor
695
737
-----------------------
696
738
697
739
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.
702
756
703
757
sys.implementation.supports_isolated_interpreters
704
758
-------------------------------------------------
0 commit comments