Skip to content

Commit 9d7a1f4

Browse files
author
Golf Player
committed
Since potentially everything is sync code and blocks the eventloop, maybe ensure_future does things the right way
1 parent b9faf64 commit 9d7a1f4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

nbclient/util.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,9 @@ async def ensure_async(obj):
9494
def run_hook(hook, *args):
9595
if hook is None:
9696
return
97-
loop = asyncio.get_event_loop()
98-
loop.call_soon(hook, *args)
97+
if inspect.isawaitable(hook):
98+
loop = asyncio.get_event_loop()
99+
future = loop.run_in_executor(None, hook, *args)
100+
else:
101+
future = hook(*args)
102+
asyncio.ensure_future(future)

0 commit comments

Comments
 (0)