mirror of https://github.com/python/cpython
gh-109413: Enable `strict_optional = true` for `libregrtest/run_workers` (#126855)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
2c0a21c1aa
commit
a1d9c8aa80
|
@ -22,10 +22,6 @@ disallow_untyped_defs = False
|
||||||
check_untyped_defs = False
|
check_untyped_defs = False
|
||||||
warn_return_any = False
|
warn_return_any = False
|
||||||
|
|
||||||
# Enable --strict-optional for these ASAP:
|
|
||||||
[mypy-Lib.test.libregrtest.run_workers.*]
|
|
||||||
strict_optional = False
|
|
||||||
|
|
||||||
# Various internal modules that typeshed deliberately doesn't have stubs for:
|
# Various internal modules that typeshed deliberately doesn't have stubs for:
|
||||||
[mypy-_abc.*,_opcode.*,_overlapped.*,_testcapi.*,_testinternalcapi.*,test.*]
|
[mypy-_abc.*,_opcode.*,_overlapped.*,_testcapi.*,_testinternalcapi.*,test.*]
|
||||||
ignore_missing_imports = True
|
ignore_missing_imports = True
|
||||||
|
|
|
@ -102,6 +102,9 @@ class WorkerError(Exception):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
|
||||||
|
_NOT_RUNNING = "<not running>"
|
||||||
|
|
||||||
|
|
||||||
class WorkerThread(threading.Thread):
|
class WorkerThread(threading.Thread):
|
||||||
def __init__(self, worker_id: int, runner: "RunWorkers") -> None:
|
def __init__(self, worker_id: int, runner: "RunWorkers") -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
@ -111,8 +114,8 @@ class WorkerThread(threading.Thread):
|
||||||
self.output = runner.output
|
self.output = runner.output
|
||||||
self.timeout = runner.worker_timeout
|
self.timeout = runner.worker_timeout
|
||||||
self.log = runner.log
|
self.log = runner.log
|
||||||
self.test_name: TestName | None = None
|
self.test_name = _NOT_RUNNING
|
||||||
self.start_time: float | None = None
|
self.start_time = time.monotonic()
|
||||||
self._popen: subprocess.Popen[str] | None = None
|
self._popen: subprocess.Popen[str] | None = None
|
||||||
self._killed = False
|
self._killed = False
|
||||||
self._stopped = False
|
self._stopped = False
|
||||||
|
@ -129,7 +132,7 @@ class WorkerThread(threading.Thread):
|
||||||
popen = self._popen
|
popen = self._popen
|
||||||
if popen is not None:
|
if popen is not None:
|
||||||
dt = time.monotonic() - self.start_time
|
dt = time.monotonic() - self.start_time
|
||||||
info.extend((f'pid={self._popen.pid}',
|
info.extend((f'pid={popen.pid}',
|
||||||
f'time={format_duration(dt)}'))
|
f'time={format_duration(dt)}'))
|
||||||
return '<%s>' % ' '.join(info)
|
return '<%s>' % ' '.join(info)
|
||||||
|
|
||||||
|
@ -401,7 +404,7 @@ class WorkerThread(threading.Thread):
|
||||||
except WorkerError as exc:
|
except WorkerError as exc:
|
||||||
mp_result = exc.mp_result
|
mp_result = exc.mp_result
|
||||||
finally:
|
finally:
|
||||||
self.test_name = None
|
self.test_name = _NOT_RUNNING
|
||||||
mp_result.result.duration = time.monotonic() - self.start_time
|
mp_result.result.duration = time.monotonic() - self.start_time
|
||||||
self.output.put((False, mp_result))
|
self.output.put((False, mp_result))
|
||||||
|
|
||||||
|
@ -416,6 +419,9 @@ class WorkerThread(threading.Thread):
|
||||||
|
|
||||||
def _wait_completed(self) -> None:
|
def _wait_completed(self) -> None:
|
||||||
popen = self._popen
|
popen = self._popen
|
||||||
|
# only needed for mypy:
|
||||||
|
if popen is None:
|
||||||
|
raise ValueError("Should never access `._popen` before calling `.run()`")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
popen.wait(WAIT_COMPLETED_TIMEOUT)
|
popen.wait(WAIT_COMPLETED_TIMEOUT)
|
||||||
|
@ -483,7 +489,7 @@ class RunWorkers:
|
||||||
self.worker_timeout: float | None = min(self.timeout * 1.5, self.timeout + 5 * 60)
|
self.worker_timeout: float | None = min(self.timeout * 1.5, self.timeout + 5 * 60)
|
||||||
else:
|
else:
|
||||||
self.worker_timeout = None
|
self.worker_timeout = None
|
||||||
self.workers: list[WorkerThread] | None = None
|
self.workers: list[WorkerThread] = []
|
||||||
|
|
||||||
jobs = self.runtests.get_jobs()
|
jobs = self.runtests.get_jobs()
|
||||||
if jobs is not None:
|
if jobs is not None:
|
||||||
|
@ -503,7 +509,7 @@ class RunWorkers:
|
||||||
processes = plural(nworkers, "process", "processes")
|
processes = plural(nworkers, "process", "processes")
|
||||||
msg = (f"Run {tests} in parallel using "
|
msg = (f"Run {tests} in parallel using "
|
||||||
f"{nworkers} worker {processes}")
|
f"{nworkers} worker {processes}")
|
||||||
if self.timeout:
|
if self.timeout and self.worker_timeout is not None:
|
||||||
msg += (" (timeout: %s, worker timeout: %s)"
|
msg += (" (timeout: %s, worker timeout: %s)"
|
||||||
% (format_duration(self.timeout),
|
% (format_duration(self.timeout),
|
||||||
format_duration(self.worker_timeout)))
|
format_duration(self.worker_timeout)))
|
||||||
|
@ -555,7 +561,7 @@ class RunWorkers:
|
||||||
if mp_result.err_msg:
|
if mp_result.err_msg:
|
||||||
# WORKER_BUG
|
# WORKER_BUG
|
||||||
text += ' (%s)' % mp_result.err_msg
|
text += ' (%s)' % mp_result.err_msg
|
||||||
elif (result.duration >= PROGRESS_MIN_TIME and not pgo):
|
elif (result.duration and result.duration >= PROGRESS_MIN_TIME and not pgo):
|
||||||
text += ' (%s)' % format_duration(result.duration)
|
text += ' (%s)' % format_duration(result.duration)
|
||||||
if not pgo:
|
if not pgo:
|
||||||
running = get_running(self.workers)
|
running = get_running(self.workers)
|
||||||
|
|
Loading…
Reference in New Issue