MCPcopy Index your code
hub / github.com/python/cpython / run_coroutine_threadsafe

Function run_coroutine_threadsafe

Lib/asyncio/tasks.py:1007–1027  ·  view source on GitHub ↗

Submit a coroutine object to a given event loop. Return a concurrent.futures.Future to access the result.

(coro, loop)

Source from the content-addressed store, hash-verified

1005
1006
1007def run_coroutine_threadsafe(coro, loop):
1008 """Submit a coroutine object to a given event loop.
1009
1010 Return a concurrent.futures.Future to access the result.
1011 """
1012 if not coroutines.iscoroutine(coro):
1013 raise TypeError('A coroutine object is required')
1014 future = concurrent.futures.Future()
1015
1016 def callback():
1017 try:
1018 futures._chain_future(ensure_future(coro, loop=loop), future)
1019 except (SystemExit, KeyboardInterrupt):
1020 raise
1021 except BaseException as exc:
1022 if future.set_running_or_notify_cancel():
1023 future.set_exception(exc)
1024 raise
1025
1026 loop.call_soon_threadsafe(callback)
1027 return future
1028
1029
1030def create_eager_task_factory(custom_task_constructor):

Callers

nothing calls this directly

Calls 1

call_soon_threadsafeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…