Wait for the futures in the given sequence to complete. Args: fs: The sequence of Futures (possibly created by different Executors) to wait upon. timeout: The maximum number of seconds to wait. If None, then there is no limit on the wait time. ret
(fs, timeout=None, return_when=ALL_COMPLETED)
| 255 | DoneAndNotDoneFutures = collections.namedtuple( |
| 256 | 'DoneAndNotDoneFutures', 'done not_done') |
| 257 | def wait(fs, timeout=None, return_when=ALL_COMPLETED): |
| 258 | """Wait for the futures in the given sequence to complete. |
| 259 | |
| 260 | Args: |
| 261 | fs: The sequence of Futures (possibly created by different Executors) to |
| 262 | wait upon. |
| 263 | timeout: The maximum number of seconds to wait. If None, then there |
| 264 | is no limit on the wait time. |
| 265 | return_when: Indicates when this function should return. The options |
| 266 | are: |
| 267 | |
| 268 | FIRST_COMPLETED - Return when any future finishes or is |
| 269 | cancelled. |
| 270 | FIRST_EXCEPTION - Return when any future finishes by raising an |
| 271 | exception. If no future raises an exception |
| 272 | then it is equivalent to ALL_COMPLETED. |
| 273 | ALL_COMPLETED - Return when all futures finish or are cancelled. |
| 274 | |
| 275 | Returns: |
| 276 | A named 2-tuple of sets. The first set, named 'done', contains the |
| 277 | futures that completed (is finished or cancelled) before the wait |
| 278 | completed. The second set, named 'not_done', contains uncompleted |
| 279 | futures. Duplicate futures given to *fs* are removed and will be |
| 280 | returned only once. |
| 281 | """ |
| 282 | fs = set(fs) |
| 283 | with _AcquireFutures(fs): |
| 284 | done = {f for f in fs |
| 285 | if f._state in [CANCELLED_AND_NOTIFIED, FINISHED]} |
| 286 | not_done = fs - done |
| 287 | if (return_when == FIRST_COMPLETED) and done: |
| 288 | return DoneAndNotDoneFutures(done, not_done) |
| 289 | elif (return_when == FIRST_EXCEPTION) and done: |
| 290 | if any(f for f in done |
| 291 | if not f.cancelled() and f.exception() is not None): |
| 292 | return DoneAndNotDoneFutures(done, not_done) |
| 293 | |
| 294 | if len(done) == len(fs): |
| 295 | return DoneAndNotDoneFutures(done, not_done) |
| 296 | |
| 297 | waiter = _create_and_install_waiters(fs, return_when) |
| 298 | |
| 299 | waiter.event.wait(timeout) |
| 300 | for f in fs: |
| 301 | with f._condition: |
| 302 | f._waiters.remove(waiter) |
| 303 | |
| 304 | done.update(waiter.finished_futures) |
| 305 | return DoneAndNotDoneFutures(done, fs - done) |
| 306 | |
| 307 | |
| 308 | def _result_or_cancel(fut, timeout=None): |
nothing calls this directly
no test coverage detected
searching dependent graphs…