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
21 changes: 21 additions & 0 deletions Lib/test/test_interpreters/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2204,6 +2204,27 @@ def test_whence(self):
whence = eval(text)
self.assertEqual(whence, _interpreters.WHENCE_LEGACY_CAPI)

def test_get_current_missing(self):
with self.subTest('main'):
main, *_ = _interpreters.get_main()
interpid, whence = _interpreters.get_current()
self.assertEqual(interpid, main)
self.assertEqual(whence, _interpreters.WHENCE_RUNTIME)

script = f"""
import contextvars
from concurrent.interpreters import get_current
print(getattr(contextvars.Token, "MISSING", "'doesn't exist'"))
"""
def parse_stdout(text):
interpid, whence = eval(text)
return interpid, whence

with self.subTest('from concurrent.interpreters'):
orig = _interpreters.create()
text = self.run_and_capture(orig, script)
self.assertEqual(text.strip(), "<Token.MISSING>")

def test_is_running(self):
def check(interpid, expected):
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix Context initialization so that all subinterpreters are assigned the
MISSING value.
4 changes: 0 additions & 4 deletions Python/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -1360,10 +1360,6 @@ get_token_missing(void)
PyStatus
_PyContext_Init(PyInterpreterState *interp)
{
if (!_Py_IsMainInterpreter(interp)) {
return _PyStatus_OK();
}

PyObject *missing = get_token_missing();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_token_missing is using Singleton value so it is safe to use.

if (PyDict_SetItemString(
_PyType_GetDict(&PyContextToken_Type), "MISSING", missing))
Expand Down
Loading