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