MCPcopy Create free account
hub / github.com/EasyIME/PIME / multi_future

Function multi_future

python/python3/tornado/gen.py:492–552  ·  view source on GitHub ↗

Wait for multiple asynchronous futures in parallel. Since Tornado 6.0, this function is exactly the same as `multi`. .. versionadded:: 4.0 .. versionchanged:: 4.2 If multiple ``Futures`` fail, any exceptions after the first (which is raised) will be logged. Added the ``q

(
    children: Union[List[_Yieldable], Dict[Any, _Yieldable]],
    quiet_exceptions: "Union[Type[Exception], Tuple[Type[Exception], ...]]" = (),
)

Source from the content-addressed store, hash-verified

490
491
492def multi_future(
493 children: Union[List[_Yieldable], Dict[Any, _Yieldable]],
494 quiet_exceptions: "Union[Type[Exception], Tuple[Type[Exception], ...]]" = (),
495) -> "Union[Future[List], Future[Dict]]":
496 """Wait for multiple asynchronous futures in parallel.
497
498 Since Tornado 6.0, this function is exactly the same as `multi`.
499
500 .. versionadded:: 4.0
501
502 .. versionchanged:: 4.2
503 If multiple ``Futures`` fail, any exceptions after the first (which is
504 raised) will be logged. Added the ``quiet_exceptions``
505 argument to suppress this logging for selected exception types.
506
507 .. deprecated:: 4.3
508 Use `multi` instead.
509 """
510 if isinstance(children, dict):
511 keys = list(children.keys()) # type: Optional[List]
512 children_seq = children.values() # type: Iterable
513 else:
514 keys = None
515 children_seq = children
516 children_futs = list(map(convert_yielded, children_seq))
517 assert all(is_future(i) or isinstance(i, _NullFuture) for i in children_futs)
518 unfinished_children = set(children_futs)
519
520 future = _create_future()
521 if not children_futs:
522 future_set_result_unless_cancelled(future, {} if keys is not None else [])
523
524 def callback(fut: Future) -> None:
525 unfinished_children.remove(fut)
526 if not unfinished_children:
527 result_list = []
528 for f in children_futs:
529 try:
530 result_list.append(f.result())
531 except Exception as e:
532 if future.done():
533 if not isinstance(e, quiet_exceptions):
534 app_log.error(
535 "Multiple exceptions in yield list", exc_info=True
536 )
537 else:
538 future_set_exc_info(future, sys.exc_info())
539 if not future.done():
540 if keys is not None:
541 future_set_result_unless_cancelled(
542 future, dict(zip(keys, result_list))
543 )
544 else:
545 future_set_result_unless_cancelled(future, result_list)
546
547 listening = set() # type: Set[Future]
548 for f in children_futs:
549 if f not in listening:

Callers 1

multiFunction · 0.85

Calls 7

is_futureFunction · 0.90
future_add_done_callbackFunction · 0.90
listFunction · 0.85
allFunction · 0.85
_create_futureFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected