@@ -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
@@ -401,7 +404,7 @@ def run(self) -> None:
401
404
except WorkerError as exc :
402
405
mp_result = exc .mp_result
403
406
finally :
404
- self .test_name = None
407
+ self .test_name = _NOT_RUNNING
405
408
mp_result .result .duration = time .monotonic () - self .start_time
406
409
self .output .put ((False , mp_result ))
407
410
@@ -416,6 +419,9 @@ def run(self) -> None:
416
419
417
420
def _wait_completed (self ) -> None :
418
421
popen = self ._popen
422
+ # only needed for mypy:
423
+ if popen is None :
424
+ raise ValueError ("Should never access `._popen` before calling `.run()`" )
419
425
420
426
try :
421
427
popen .wait (WAIT_COMPLETED_TIMEOUT )
@@ -483,7 +489,7 @@ def __init__(self, num_workers: int, runtests: RunTests,
483
489
self .worker_timeout : float | None = min (self .timeout * 1.5 , self .timeout + 5 * 60 )
484
490
else :
485
491
self .worker_timeout = None
486
- self .workers : list [WorkerThread ] | None = None
492
+ self .workers : list [WorkerThread ] = []
487
493
488
494
jobs = self .runtests .get_jobs ()
489
495
if jobs is not None :
@@ -503,7 +509,7 @@ def start_workers(self) -> None:
503
509
processes = plural (nworkers , "process" , "processes" )
504
510
msg = (f"Run { tests } in parallel using "
505
511
f"{ nworkers } worker { processes } " )
506
- if self .timeout :
512
+ if self .timeout and self . worker_timeout is not None :
507
513
msg += (" (timeout: %s, worker timeout: %s)"
508
514
% (format_duration (self .timeout ),
509
515
format_duration (self .worker_timeout )))
@@ -555,7 +561,7 @@ def display_result(self, mp_result: MultiprocessResult) -> None:
555
561
if mp_result .err_msg :
556
562
# WORKER_BUG
557
563
text += ' (%s)' % mp_result .err_msg
558
- elif (result .duration >= PROGRESS_MIN_TIME and not pgo ):
564
+ elif (result .duration and result . duration >= PROGRESS_MIN_TIME and not pgo ):
559
565
text += ' (%s)' % format_duration (result .duration )
560
566
if not pgo :
561
567
running = get_running (self .workers )
0 commit comments