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

Function spawn_repl

Lib/test/test_repl.py:31–64  ·  view source on GitHub ↗

Run the Python REPL with the given arguments. kw is extra keyword args to pass to subprocess.Popen. Returns a Popen object.

(*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, custom=False, isolated=True, **kw)

Source from the content-addressed store, hash-verified

29
30
31def spawn_repl(*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, custom=False, isolated=True, **kw):
32 """Run the Python REPL with the given arguments.
33
34 kw is extra keyword args to pass to subprocess.Popen. Returns a Popen
35 object.
36 """
37
38 # To run the REPL without using a terminal, spawn python with the command
39 # line option '-i' and the process name set to '<stdin>'.
40 # The directory of argv[0] must match the directory of the Python
41 # executable for the Popen() call to python to succeed as the directory
42 # path may be used by PyConfig_Get("module_search_paths") to build the
43 # default module search path.
44 stdin_fname = os.path.join(os.path.dirname(sys.executable), "<stdin>")
45 cmd_line = [stdin_fname]
46 # Isolated mode implies -EPs and ignores PYTHON* variables.
47 if isolated:
48 cmd_line.append('-I')
49 # Don't re-run the built-in REPL from interactive mode
50 # if we're testing a custom REPL (such as the asyncio REPL).
51 if not custom:
52 cmd_line.append('-i')
53 cmd_line.extend(args)
54
55 # Set TERM=vt100, for the rationale see the comments in spawn_python() of
56 # test.support.script_helper.
57 env = kw.setdefault('env', dict(os.environ))
58 env['TERM'] = 'vt100'
59 return subprocess.Popen(cmd_line,
60 executable=sys.executable,
61 text=True,
62 stdin=subprocess.PIPE,
63 stdout=stdout, stderr=stderr,
64 **kw)
65
66
67spawn_asyncio_repl = partial(spawn_repl, "-m", "asyncio", custom=True)

Calls 5

joinMethod · 0.45
dirnameMethod · 0.45
appendMethod · 0.45
extendMethod · 0.45
setdefaultMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…