MCPcopy Create free account
hub / github.com/apache/mesos / as_completed

Function as_completed

src/python/cli/src/mesos/futures.py:129–161  ·  view source on GitHub ↗
(futures, timeout=None)

Source from the content-addressed store, hash-verified

127
128
129 def as_completed(futures, timeout=None):
130 # Record the start time in order to determine the remaining
131 # timeout as futures are completed.
132 start = time.time()
133
134 # Use a queue to collect the done futures.
135 queue = Queue()
136
137 # Define a helper for the future "done callback".
138 def done(future):
139 queue.put(future)
140
141 # Add a "done callback" for each future.
142 for future in futures:
143 future.add_done_callback(done)
144
145 # Helper to determine the remaining timeout.
146 def remaining():
147 if timeout is None:
148 return None
149 end = start + timeout
150 remaining = end - time.time()
151 return remaining if remaining >= 0 else 0
152
153 # Now wait until all the futures have completed or we timeout.
154 finished = 0
155 while finished < len(futures):
156 try:
157 yield queue.get(timeout=remaining())
158 except Empty:
159 raise TimeoutError()
160 else:
161 finished += 1
162
163
164class ThreadingExecutor(Executor):

Callers

nothing calls this directly

Calls 6

getMethod · 0.95
QueueClass · 0.85
remainingFunction · 0.85
TimeoutErrorClass · 0.85
add_done_callbackMethod · 0.80
timeMethod · 0.45

Tested by

no test coverage detected