MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _ensure_future

Function _ensure_future

tools/python-3.11.9-amd64/Lib/asyncio/tasks.py:662–684  ·  view source on GitHub ↗
(coro_or_future, *, loop=None)

Source from the content-addressed store, hash-verified

660
661
662def _ensure_future(coro_or_future, *, loop=None):
663 if futures.isfuture(coro_or_future):
664 if loop is not None and loop is not futures._get_loop(coro_or_future):
665 raise ValueError('The future belongs to a different loop than '
666 'the one specified as the loop argument')
667 return coro_or_future
668 called_wrap_awaitable = False
669 if not coroutines.iscoroutine(coro_or_future):
670 if inspect.isawaitable(coro_or_future):
671 coro_or_future = _wrap_awaitable(coro_or_future)
672 called_wrap_awaitable = True
673 else:
674 raise TypeError('An asyncio.Future, a coroutine or an awaitable '
675 'is required')
676
677 if loop is None:
678 loop = events._get_event_loop(stacklevel=4)
679 try:
680 return loop.create_task(coro_or_future)
681 except RuntimeError:
682 if not called_wrap_awaitable:
683 coro_or_future.close()
684 raise
685
686
687@types.coroutine

Callers 3

ensure_futureFunction · 0.85
gatherFunction · 0.85
shieldFunction · 0.85

Calls 4

_wrap_awaitableFunction · 0.85
_get_loopMethod · 0.80
create_taskMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected