MCPcopy Index your code
hub / github.com/python/cpython / Interpreter

Class Interpreter

Lib/test/test__interpchannels.py:75–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73
74
75class Interpreter(namedtuple('Interpreter', 'name id')):
76
77 @classmethod
78 def from_raw(cls, raw):
79 if isinstance(raw, cls):
80 return raw
81 elif isinstance(raw, str):
82 return cls(raw)
83 else:
84 raise NotImplementedError
85
86 def __new__(cls, name=None, id=None):
87 main, *_ = _interpreters.get_main()
88 if id == main:
89 if not name:
90 name = 'main'
91 elif name != 'main':
92 raise ValueError(
93 'name mismatch (expected "main", got "{}")'.format(name))
94 id = main
95 elif id is not None:
96 if not name:
97 name = 'interp'
98 elif name == 'main':
99 raise ValueError('name mismatch (unexpected "main")')
100 assert isinstance(id, int), repr(id)
101 elif not name or name == 'main':
102 name = 'main'
103 id = main
104 else:
105 id = _interpreters.create()
106 self = super().__new__(cls, name, id)
107 return self
108
109
110# XXX expect_channel_closed() is unnecessary once we improve exc propagation.

Callers 1

_get_interpreterMethod · 0.70

Calls 1

namedtupleFunction · 0.90

Tested by 1

_get_interpreterMethod · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…