Skip to content
Merged
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
Return an InterpreterID from get_main().
  • Loading branch information
ericsnowcurrently committed May 16, 2018
commit cbbc5627dcef9bc51694a0b92bee0193a92b7276
16 changes: 14 additions & 2 deletions Lib/test/test__xxsubinterpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,16 @@ def test_main(self):
main = interpreters.get_main()
cur = interpreters.get_current()
self.assertEqual(cur, main)
self.assertIsInstance(cur, interpreters.InterpreterID)

def test_subinterpreter(self):
main = interpreters.get_main()
interp = interpreters.create()
out = _run_output(interp, dedent("""
import _xxsubinterpreters as _interpreters
print(_interpreters.get_current())
cur = _interpreters.get_current()
print(cur)
assert isinstance(cur, _interpreters.InterpreterID)
"""))
cur = int(out.strip())
_, expected = interpreters.list_all()
Expand All @@ -176,13 +179,16 @@ def test_from_main(self):
[expected] = interpreters.list_all()
main = interpreters.get_main()
self.assertEqual(main, expected)
self.assertIsInstance(main, interpreters.InterpreterID)

def test_from_subinterpreter(self):
[expected] = interpreters.list_all()
interp = interpreters.create()
out = _run_output(interp, dedent("""
import _xxsubinterpreters as _interpreters
print(_interpreters.get_main())
main = _interpreters.get_main()
print(main)
assert isinstance(main, _interpreters.InterpreterID)
"""))
main = int(out.strip())
self.assertEqual(main, expected)
Expand Down Expand Up @@ -293,6 +299,7 @@ class CreateTests(TestBase):

def test_in_main(self):
id = interpreters.create()
self.assertIsInstance(id, interpreters.InterpreterID)

self.assertIn(id, interpreters.list_all())

Expand Down Expand Up @@ -328,6 +335,7 @@ def test_in_subinterpreter(self):
import _xxsubinterpreters as _interpreters
id = _interpreters.create()
print(id)
assert isinstance(id, _interpreters.InterpreterID)
"""))
id2 = int(out.strip())

Expand Down Expand Up @@ -892,6 +900,10 @@ def test_equality(self):

class ChannelTests(TestBase):

def test_create_cid(self):
cid = interpreters.channel_create()
self.assertIsInstance(cid, interpreters.ChannelID)

def test_sequential_ids(self):
before = interpreters.channel_list_all()
id1 = interpreters.channel_create()
Expand Down
3 changes: 2 additions & 1 deletion Modules/_xxsubinterpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2285,7 +2285,8 @@ static PyObject *
interp_get_main(PyObject *self, PyObject *Py_UNUSED(ignored))
{
// Currently, 0 is always the main interpreter.
return PyLong_FromLongLong(0);
PY_INT64_T id = 0;
return (PyObject *)newinterpid(&InterpreterIDtype, id, 0);
}

PyDoc_STRVAR(get_main_doc,
Expand Down