Skip to content

Commit a72de93

Browse files
bpo-36670: regrtest bug fixes (GH-16537)
* Fix TestWorkerProcess.__repr__(): start_time is only valid if _popen is not None. * Fix _kill(): don't set _killed to True if _popen is None. * _run_process(): only set _killed to False after calling run_test_in_subprocess(). (cherry picked from commit 2ea71a0) Co-authored-by: Victor Stinner <[email protected]>
1 parent a11df75 commit a72de93

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

Lib/test/libregrtest/runtest_mp.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,27 +120,28 @@ def __init__(self, worker_id, pending, output, ns, timeout):
120120
def __repr__(self):
121121
info = [f'TestWorkerProcess #{self.worker_id}']
122122
if self.is_alive():
123-
dt = time.monotonic() - self.start_time
124-
info.append("running for %s" % format_duration(dt))
123+
info.append("running")
125124
else:
126125
info.append('stopped')
127126
test = self.current_test_name
128127
if test:
129128
info.append(f'test={test}')
130129
popen = self._popen
131-
if popen:
132-
info.append(f'pid={popen.pid}')
130+
if popen is not None:
131+
dt = time.monotonic() - self.start_time
132+
info.extend((f'pid={self._popen.pid}',
133+
f'time={format_duration(dt)}'))
133134
return '<%s>' % ' '.join(info)
134135

135136
def _kill(self):
136-
if self._killed:
137-
return
138-
self._killed = True
139-
140137
popen = self._popen
141138
if popen is None:
142139
return
143140

141+
if self._killed:
142+
return
143+
self._killed = True
144+
144145
print(f"Kill {self}", file=sys.stderr, flush=True)
145146
try:
146147
popen.kill()
@@ -177,9 +178,10 @@ def _run_process(self, test_name):
177178

178179
self.current_test_name = test_name
179180
try:
181+
popen = run_test_in_subprocess(test_name, self.ns)
182+
180183
self._killed = False
181-
self._popen = run_test_in_subprocess(test_name, self.ns)
182-
popen = self._popen
184+
self._popen = popen
183185
except:
184186
self.current_test_name = None
185187
raise

0 commit comments

Comments
 (0)