Skip to content

Commit aa05e0e

Browse files
committed
[lit] Synthesize artificial deadline
We always want to use a deadline when calling `result.await`. Let's synthesize an artificial deadline (positive infinity) to simplify code and do less busy waiting. llvm-svn: 375129
1 parent d25c766 commit aa05e0e

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

llvm/utils/lit/lit/run.py

+5-13
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def acquire(self): pass
1212
def release(self): pass
1313

1414
def create_run(tests, lit_config, workers, progress_callback, max_time):
15+
# TODO(yln) assert workers > 0
1516
if workers == 1:
1617
return SerialRun(tests, lit_config, progress_callback, max_time)
1718
return ParallelRun(tests, lit_config, progress_callback, max_time, workers)
@@ -107,11 +108,7 @@ def __init__(self, tests, lit_config, progress_callback, max_time, workers):
107108
self.workers = workers
108109

109110
def _execute(self):
110-
# We need to issue many wait calls, so compute the final deadline and
111-
# subtract time.time() from that as we go along.
112-
deadline = None
113-
if self.max_time:
114-
deadline = time.time() + self.max_time
111+
deadline = (time.time() + self.max_time) if self.max_time else float('inf')
115112

116113
semaphores = {
117114
k: NopSemaphore() if v is None else
@@ -146,15 +143,10 @@ def console_ctrl_handler(type):
146143
# Wait for all results to come in. The callback that runs in the
147144
# parent process will update the display.
148145
for a in async_results:
149-
if deadline:
150-
a.wait(deadline - time.time())
151-
else:
152-
# Python condition variables cannot be interrupted unless
153-
# they have a timeout. This can make lit unresponsive to
154-
# KeyboardInterrupt, so do a busy wait with a timeout.
155-
while not a.ready():
156-
a.wait(1)
146+
timeout = deadline - time.time()
147+
a.wait(timeout)
157148
if not a.successful():
149+
# TODO(yln): this also raises on a --max-time time
158150
a.get() # Exceptions raised here come from the worker.
159151
if self.hit_max_failures:
160152
break

0 commit comments

Comments
 (0)