Skip to content

Commit 52267df

Browse files
committed
wrap do_execute in a Future
for ipykernel 5 (gen.maybe_future) compatibility
1 parent fe0a07f commit 52267df

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

ipyparallel/engine/kernel.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""IPython kernel for parallel computing"""
2+
import asyncio
23
import inspect
34
import sys
45

@@ -193,13 +194,22 @@ def do_apply(self, content, bufs, msg_id, reply_metadata):
193194

194195
return reply_content, result_buf
195196

196-
async def do_execute(self, *args, **kwargs):
197-
reply_content = super().do_execute(*args, **kwargs)
198-
if inspect.isawaitable(reply_content):
199-
reply_content = await reply_content
200-
if reply_content['status'] == 'error':
201-
reply_content["engine_info"] = self.get_engine_info(method="execute")
202-
return reply_content
197+
def do_execute(self, *args, **kwargs):
198+
super_execute = super().do_execute(*args, **kwargs)
199+
200+
async def _do_execute():
201+
if inspect.isawaitable(super_execute):
202+
reply_content = await super_execute
203+
else:
204+
reply_content = super_execute
205+
# add engine info
206+
if reply_content['status'] == 'error':
207+
reply_content["engine_info"] = self.get_engine_info(method="execute")
208+
return reply_content
209+
210+
# ipykernel 5 uses gen.maybe_future which doesn't accept async def coroutines,
211+
# but it does accept asyncio.Futures
212+
return asyncio.ensure_future(_do_execute())
203213

204214
# Control messages for msgspec extensions:
205215

0 commit comments

Comments
 (0)