@@ -102,6 +102,9 @@ def __init__(self,
102
102
super ().__init__ ()
103
103
104
104
105
+ _NOT_RUNNING = "<not running>"
106
+
107
+
105
108
class WorkerThread (threading .Thread ):
106
109
def __init__ (self , worker_id : int , runner : "RunWorkers" ) -> None :
107
110
super ().__init__ ()
@@ -111,8 +114,8 @@ def __init__(self, worker_id: int, runner: "RunWorkers") -> None:
111
114
self .output = runner .output
112
115
self .timeout = runner .worker_timeout
113
116
self .log = runner .log
114
- self .test_name : TestName | None = None
115
- self .start_time : float | None = None
117
+ self .test_name = _NOT_RUNNING
118
+ self .start_time = time . monotonic ()
116
119
self ._popen : subprocess .Popen [str ] | None = None
117
120
self ._killed = False
118
121
self ._stopped = False
@@ -129,7 +132,7 @@ def __repr__(self) -> str:
129
132
popen = self ._popen
130
133
if popen is not None :
131
134
dt = time .monotonic () - self .start_time
132
- info .extend ((f'pid={ self . _popen .pid } ' ,
135
+ info .extend ((f'pid={ popen .pid } ' ,
133
136
f'time={ format_duration (dt )} ' ))
134
137
return '<%s>' % ' ' .join (info )
135
138
@@ -395,7 +398,7 @@ def run(self) -> None:
395
398
except WorkerError as exc :
396
399
mp_result = exc .mp_result
397
400
finally :
398
- self .test_name = None
401
+ self .test_name = _NOT_RUNNING
399
402
mp_result .result .duration = time .monotonic () - self .start_time
400
403
self .output .put ((False , mp_result ))
401
404
@@ -410,6 +413,9 @@ def run(self) -> None:
410
413
411
414
def _wait_completed (self ) -> None :
412
415
popen = self ._popen
416
+ # only needed for mypy:
417
+ if popen is None :
418
+ raise ValueError ("Should never access `._popen` before calling `.run()`" )
413
419
414
420
try :
415
421
popen .wait (WAIT_COMPLETED_TIMEOUT )
@@ -477,7 +483,7 @@ def __init__(self, num_workers: int, runtests: RunTests,
477
483
self .worker_timeout : float | None = min (self .timeout * 1.5 , self .timeout + 5 * 60 )
478
484
else :
479
485
self .worker_timeout = None
480
- self .workers : list [WorkerThread ] | None = None
486
+ self .workers : list [WorkerThread ] = []
481
487
482
488
jobs = self .runtests .get_jobs ()
483
489
if jobs is not None :
@@ -497,7 +503,7 @@ def start_workers(self) -> None:
497
503
processes = plural (nworkers , "process" , "processes" )
498
504
msg = (f"Run { tests } in parallel using "
499
505
f"{ nworkers } worker { processes } " )
500
- if self .timeout :
506
+ if self .timeout and self . worker_timeout is not None :
501
507
msg += (" (timeout: %s, worker timeout: %s)"
502
508
% (format_duration (self .timeout ),
503
509
format_duration (self .worker_timeout )))
@@ -549,7 +555,7 @@ def display_result(self, mp_result: MultiprocessResult) -> None:
549
555
if mp_result .err_msg :
550
556
# WORKER_BUG
551
557
text += ' (%s)' % mp_result .err_msg
552
- elif (result .duration >= PROGRESS_MIN_TIME and not pgo ):
558
+ elif (result .duration and result . duration >= PROGRESS_MIN_TIME and not pgo ):
553
559
text += ' (%s)' % format_duration (result .duration )
554
560
if not pgo :
555
561
running = get_running (self .workers )
0 commit comments