Skip to content

Commit

Permalink
Address review
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Nov 15, 2024
1 parent a4e1071 commit ed9a8e3
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions Lib/test/libregrtest/run_workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ def __init__(self,
super().__init__()


_NOT_RUNNING = "<not running>"


class WorkerThread(threading.Thread):
def __init__(self, worker_id: int, runner: "RunWorkers") -> None:
super().__init__()
Expand All @@ -111,19 +114,12 @@ def __init__(self, worker_id: int, runner: "RunWorkers") -> None:
self.output = runner.output
self.timeout = runner.worker_timeout
self.log = runner.log
self.test_name: TestName | None = None
self.start_time: float | None = None
self.test_name = _NOT_RUNNING
self.start_time = 0.0
self._popen: subprocess.Popen[str] | None = None
self._killed = False
self._stopped = False

def current_test_name(self) -> TestName:
if self.test_name is None:
raise ValueError(
'Should never call `.current_test_name()` before calling `.run()`'
)
return self.test_name

def __repr__(self) -> str:
info = [f'WorkerThread #{self.worker_id}']
if self.is_alive():
Expand Down Expand Up @@ -318,14 +314,14 @@ def read_stdout(self, stdout_file: TextIO) -> str:
except Exception as exc:
# gh-101634: Catch UnicodeDecodeError if stdout cannot be
# decoded from encoding
raise WorkerError(self.current_test_name(),
raise WorkerError(self.test_name,
f"Cannot read process stdout: {exc}",
stdout=None,
state=State.WORKER_BUG)

def read_json(self, json_file: JsonFile, json_tmpfile: TextIO | None,
stdout: str) -> tuple[TestResult, str]:
test_name = self.current_test_name()
test_name = self.test_name
try:
if json_tmpfile is not None:
json_tmpfile.seek(0)
Expand Down Expand Up @@ -402,15 +398,15 @@ def run(self) -> None:
except StopIteration:
break

self.start_time = start_time = time.monotonic()
self.start_time = time.monotonic()
self.test_name = test_name
try:
mp_result = self._runtest(test_name)
except WorkerError as exc:
mp_result = exc.mp_result
finally:
self.test_name = None
mp_result.result.duration = time.monotonic() - start_time
self.test_name = _NOT_RUNNING
mp_result.result.duration = time.monotonic() - self.start_time
self.output.put((False, mp_result))

if mp_result.result.must_stop(fail_fast, fail_env_changed):
Expand Down

0 comments on commit ed9a8e3

Please sign in to comment.