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

Method _execute_python

Lib/test/libregrtest/main.py:677–713  ·  view source on GitHub ↗
(self, cmd, environ)

Source from the content-addressed store, hash-verified

675 python_opts.append('-E')
676
677 def _execute_python(self, cmd, environ):
678 # Make sure that messages before execv() are logged
679 sys.stdout.flush()
680 sys.stderr.flush()
681
682 cmd_text = shlex.join(cmd)
683 try:
684 # Android and iOS run tests in embedded mode. To update their
685 # Python options, see the comment in _add_ci_python_opts.
686 if not cmd[0]:
687 raise ValueError("No Python executable is present")
688
689 print(f"+ {cmd_text}", flush=True)
690 if hasattr(os, 'execv') and not MS_WINDOWS:
691 os.execv(cmd[0], cmd)
692 # On success, execv() do no return.
693 # On error, it raises an OSError.
694 else:
695 import subprocess
696 with subprocess.Popen(cmd, env=environ) as proc:
697 try:
698 proc.wait()
699 except KeyboardInterrupt:
700 # There is no need to call proc.terminate(): on CTRL+C,
701 # SIGTERM is also sent to the child process.
702 try:
703 proc.wait(timeout=EXIT_TIMEOUT)
704 except subprocess.TimeoutExpired:
705 proc.kill()
706 proc.wait()
707 sys.exit(EXITCODE_INTERRUPTED)
708
709 sys.exit(proc.returncode)
710 except Exception as exc:
711 print_warning(f"Failed to change Python options: {exc!r}\n"
712 f"Command: {cmd_text}")
713 # continue executing main()
714
715 def _add_python_opts(self) -> None:
716 python_opts: list[str] = []

Callers 1

_add_python_optsMethod · 0.95

Calls 8

hasattrFunction · 0.85
print_warningFunction · 0.70
printFunction · 0.50
flushMethod · 0.45
joinMethod · 0.45
waitMethod · 0.45
killMethod · 0.45
exitMethod · 0.45

Tested by

no test coverage detected