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

Method _from_subinterp

Lib/test/test_import/__init__.py:322–350  ·  view source on GitHub ↗
(cls, name, interpid, pipe, script_kwargs)

Source from the content-addressed store, hash-verified

320
321 @classmethod
322 def _from_subinterp(cls, name, interpid, pipe, script_kwargs):
323 r, w = pipe
324
325 # Build the script.
326 postscript = textwrap.dedent(f'''
327 # Send the result over the pipe.
328 import json
329 import os
330 os.write({w}, json.dumps(snapshot).encode())
331
332 ''')
333 _postscript = script_kwargs.get('postscript')
334 if _postscript:
335 _postscript = textwrap.dedent(_postscript).lstrip()
336 postscript += _postscript
337 script_kwargs['postscript'] = postscript.strip()
338 script = cls.build_script(name, **script_kwargs)
339
340 # Run the script.
341 if interpid is None:
342 ret = run_in_subinterp(script)
343 if ret != 0:
344 raise AssertionError(f'{ret} != 0')
345 else:
346 _interpreters.run_string(interpid, script)
347
348 # Parse the results.
349 text = os.read(r, 1000)
350 return cls.parse(text.decode())
351
352
353@force_not_colorized_test_class

Callers 1

from_subinterpMethod · 0.80

Calls 9

run_in_subinterpFunction · 0.90
build_scriptMethod · 0.80
dedentMethod · 0.45
getMethod · 0.45
lstripMethod · 0.45
stripMethod · 0.45
readMethod · 0.45
parseMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected