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().
This commit is contained in:
Victor Stinner 2019-10-02 13:35:11 +02:00 committed by GitHub
parent b9a8b8296c
commit 2ea71a07d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 10 deletions

View File

@ -120,27 +120,28 @@ class TestWorkerProcess(threading.Thread):
def __repr__(self):
info = [f'TestWorkerProcess #{self.worker_id}']
if self.is_alive():
dt = time.monotonic() - self.start_time
info.append("running for %s" % format_duration(dt))
info.append("running")
else:
info.append('stopped')
test = self.current_test_name
if test:
info.append(f'test={test}')
popen = self._popen
if popen:
info.append(f'pid={popen.pid}')
if popen is not None:
dt = time.monotonic() - self.start_time
info.extend((f'pid={self._popen.pid}',
f'time={format_duration(dt)}'))
return '<%s>' % ' '.join(info)
def _kill(self):
if self._killed:
return
self._killed = True
popen = self._popen
if popen is None:
return
if self._killed:
return
self._killed = True
print(f"Kill {self}", file=sys.stderr, flush=True)
try:
popen.kill()
@ -177,9 +178,10 @@ class TestWorkerProcess(threading.Thread):
self.current_test_name = test_name
try:
popen = run_test_in_subprocess(test_name, self.ns)
self._killed = False
self._popen = run_test_in_subprocess(test_name, self.ns)
popen = self._popen
self._popen = popen
except:
self.current_test_name = None
raise