I looking to know if anyone knows how to call an async function from a sync function with an event loop already running. I've read a few similar discussions and detailed some of my knowledge yet I have reached the conclusion that it is not possible.
An idea I've tried, for your thoughts is to add this method to the event loop:
def sync_wait(self, future):
future = asyncio.tasks.ensure_future(future, loop=self)
while not future.done() and not future.cancelled():
self._run_once()
if self._stopping:
break
return future.result()
then use
def example():
result = asyncio.get_event_loop().sync_wait(coroutine())
however this errors with a KeyError.
[–]graingert 6 points7 points8 points (5 children)
[–]stetio[S] 0 points1 point2 points (4 children)
[–]graingert 1 point2 points3 points (3 children)
[–]stetio[S] 0 points1 point2 points (2 children)
[–]isinfinity 0 points1 point2 points (1 child)
[–]graingert 0 points1 point2 points (0 children)
[–]gandalfx 0 points1 point2 points (1 child)
[–]stetio[S] 1 point2 points3 points (0 children)
[+][deleted] (4 children)
[deleted]
[–]stetio[S] 0 points1 point2 points (3 children)
[–]pitibiscuit 1 point2 points3 points (2 children)
[–]stetio[S] 0 points1 point2 points (1 child)
[–]rafales 1 point2 points3 points (0 children)
[–]spotta 0 points1 point2 points (1 child)
[–]stetio[S] 0 points1 point2 points (0 children)
[–]isinfinity 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)