Shorthand for running a function in the default background thread pool executor and awaiting the result. The nature of synchronous code is that the future returned by this function is not cancellable
(fn: Callable, *args, **kwargs)
| 8 | |
| 9 | |
| 10 | async def call_sync_from_async(fn: Callable, *args, **kwargs): |
| 11 | """Shorthand for running a function in the default background thread pool executor |
| 12 | and awaiting the result. The nature of synchronous code is that the future |
| 13 | returned by this function is not cancellable |
| 14 | """ |
| 15 | loop = asyncio.get_event_loop() |
| 16 | coro = loop.run_in_executor(None, lambda: fn(*args, **kwargs)) |
| 17 | result = await coro |
| 18 | return result |
| 19 | |
| 20 | |
| 21 | def call_async_from_sync( |
no outgoing calls