Cleanup coroutine threadsafe (#27080)
* Cleanup coroutine threadsafe * fix lint * Fix typing * Fix tests * Fix black
This commit is contained in:
parent
f4a1f2809b
commit
c1851a2d94
23 changed files with 196 additions and 232 deletions
|
@ -7,7 +7,7 @@ from asyncio.events import AbstractEventLoop
|
|||
|
||||
import asyncio
|
||||
from asyncio import ensure_future
|
||||
from typing import Any, Union, Coroutine, Callable, Generator, TypeVar, Awaitable
|
||||
from typing import Any, Coroutine, Callable, TypeVar, Awaitable
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -30,20 +30,6 @@ except AttributeError:
|
|||
loop.close()
|
||||
|
||||
|
||||
def run_coroutine_threadsafe(
|
||||
coro: Union[Coroutine, Generator], loop: AbstractEventLoop
|
||||
) -> concurrent.futures.Future:
|
||||
"""Submit a coroutine object to a given event loop.
|
||||
|
||||
Return a concurrent.futures.Future to access the result.
|
||||
"""
|
||||
ident = loop.__dict__.get("_thread_ident")
|
||||
if ident is not None and ident == threading.get_ident():
|
||||
raise RuntimeError("Cannot be called from within the event loop")
|
||||
|
||||
return asyncio.run_coroutine_threadsafe(coro, loop)
|
||||
|
||||
|
||||
def fire_coroutine_threadsafe(coro: Coroutine, loop: AbstractEventLoop) -> None:
|
||||
"""Submit a coroutine object to a given event loop.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue