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

Function strace_python

Lib/test/support/strace_helper.py:98–145  ·  view source on GitHub ↗

Run strace and return the trace. Sets strace_returncode and python_returncode to `-1` on error.

(code, strace_flags, check=True)

Source from the content-addressed store, hash-verified

96
97@support.requires_subprocess()
98def strace_python(code, strace_flags, check=True):
99 """Run strace and return the trace.
100
101 Sets strace_returncode and python_returncode to `-1` on error."""
102 res = None
103
104 def _make_error(reason, details):
105 return StraceResult(
106 strace_returncode=-1,
107 python_returncode=-1,
108 event_bytes= f"error({reason},details={details!r}) = -1".encode('utf-8'),
109 stdout=res.out if res else b"",
110 stderr=res.err if res else b"")
111
112 # Run strace, and get out the raw text
113 try:
114 res, cmd_line = run_python_until_end(
115 "-c",
116 textwrap.dedent(code),
117 __run_using_command=[_strace_binary] + strace_flags,
118 )
119 except OSError as err:
120 return _make_error("Caught OSError", err)
121
122 if check and res.rc:
123 res.fail(cmd_line)
124
125 # Get out program returncode
126 stripped = res.err.strip()
127 output = stripped.rsplit(b"\n", 1)
128 if len(output) != 2:
129 return _make_error("Expected strace events and exit code line",
130 stripped[-50:])
131
132 returncode_match = _returncode_regex.match(output[1])
133 if not returncode_match:
134 return _make_error("Expected to find returncode in last line.",
135 output[1][:50])
136
137 python_returncode = int(returncode_match["returncode"])
138 if check and python_returncode:
139 res.fail(cmd_line)
140
141 return StraceResult(strace_returncode=res.rc,
142 python_returncode=python_returncode,
143 event_bytes=output[0],
144 stdout=res.out,
145 stderr=res.err)
146
147
148def get_events(code, strace_flags, prelude, cleanup):

Callers 2

get_eventsFunction · 0.85
_can_straceFunction · 0.85

Calls 9

run_python_until_endFunction · 0.90
_make_errorFunction · 0.85
lenFunction · 0.85
StraceResultClass · 0.85
dedentMethod · 0.80
failMethod · 0.45
stripMethod · 0.45
rsplitMethod · 0.45
matchMethod · 0.45

Tested by

no test coverage detected