(futures, timeout=None)
| 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 | |
| 164 | class ThreadingExecutor(Executor): |
nothing calls this directly
no test coverage detected