Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Global initial Sub-Interpreters functions
  • Loading branch information
nanjekyejoannah committed Sep 10, 2019
commit 3f2f2f4f862fde1455fdc178265172040cd7f7e8
38 changes: 36 additions & 2 deletions Doc/library/interpreters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,42 @@
==========================================================

.. module:: interpreters
:synopsis: High-level Sub-interpreters Module.
:synopsis: High-level Sub-Interpreters Module.

**Source code:** :source:`Lib/interpreters.py`

Copy link
Copy Markdown
Contributor

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.

--------------
--------------

This module constructs higher-level interpreters interfaces on top of the lower
level :mod:`_interpreters` module.

.. versionchanged:: 3.9


This module defines the following functions:


.. function:: create()

Create a new interpreter and return a unique generated ID.

.. function:: list_all()

Return a list containing the ID of every existing interpreter.

.. function:: get_current()

Return the ID of the currently running interpreter.

.. function:: destroy(id)

Destroy the interpreter whose ID is *id*.

.. function:: get_main()

Return the ID of the main interpreter.

.. function:: run_string()

Execute the provided string in the identified interpreter.
See `PyRun_SimpleStrings`.
59 changes: 59 additions & 0 deletions Lib/interpreters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""Sub-interpreters High Level Module."""

import _interpreters

__all__ = ['create', 'list_all', 'get_current']

# Rename so that "from interpreters import *" is safe
_list_all = _interpreters.list_all
_get_current = _interpreters.get_current
_get_main = _interpreters.get_main
_run_string = _interpreters.run_string

# Global API functions

def create():
""" create() -> Interpreter

Create a new interpreter and return a unique generated ID.
"""
return _interpreters.create()

def list_all():
"""list_all() -> [Interpreter]

Return a list containing the ID of every existing interpreter.
"""
return _list_all()

def get_current():
"""get_current() -> Interpreter

Return the ID of the currently running interpreter.
"""
return _get_current()

def get_main():
"""get_main() -> ID

Return the ID of the main interpreter.
"""

return _get_main()

def destroy(id):
"""destroy(id) -> None

Destroy the identified interpreter.
"""

return _interpreters.destroy(id)

def run_string(id, script, shared):
"""run_string(id, script, shared) -> None

Execute the provided string in the identified interpreter.
See PyRun_SimpleStrings.
"""

return _run_string(id, script, shared)
Loading