MCPcopy Index your code
hub / github.com/RustPython/RustPython / _from_subinterp

Method _from_subinterp

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

Source from the content-addressed store, hash-verified

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

Callers 1

from_subinterpMethod · 0.80

Calls 10

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

Tested by

no test coverage detected