Skip to content

bpo-30439: Add a basic high-level interpreters module. #1803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Add get_main().
  • Loading branch information
ericsnowcurrently committed May 24, 2017
commit 9704487b3d726bb5d91d87ed0859a5ff6ed9cfce
5 changes: 5 additions & 0 deletions Doc/library/_interpreters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ It defines the following functions:
Return the ID of the currently running interpreter.


.. function:: get_main()

Return the ID of the main interpreter.


.. function:: is_running(id)

Return whether or not the identified interpreter is currently
Expand Down
10 changes: 10 additions & 0 deletions Lib/test/test__interpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ def test_sub(self):
self.assertEqual(id2, id1)


class GetMainTests(TestBase):

def test_main(self):
expected, = interpreters.enumerate()
main = interpreters.get_main()

self.assertEqual(main, 0)
self.assertEqual(main, expected)


class IsRunningTests(TestBase):

def test_main_running(self):
Expand Down
15 changes: 15 additions & 0 deletions Modules/_interpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,19 @@ PyDoc_STRVAR(get_current_doc,
Return the ID of current interpreter.");


static PyObject *
interp_get_main(PyObject *self)
{
// Currently, 0 is always the main interpreter.
return PyLong_FromLongLong(0);
}

PyDoc_STRVAR(get_main_doc,
"get_main() -> ID\n\
\n\
Return the ID of main interpreter.");


static PyObject *
interp_run_string(PyObject *self, PyObject *args)
{
Expand Down Expand Up @@ -455,6 +468,8 @@ static PyMethodDef module_functions[] = {
METH_NOARGS, enumerate_doc},
{"get_current", (PyCFunction)interp_get_current,
METH_NOARGS, get_current_doc},
{"get_main", (PyCFunction)interp_get_main,
METH_NOARGS, get_main_doc},
{"is_running", (PyCFunction)interp_is_running,
METH_VARARGS, is_running_doc},

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy