Skip to content

Commit 583dc40

Browse files
committed
Handle synchronous message handlers
1 parent ee78349 commit 583dc40

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

ipykernel/kernelbase.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from functools import partial
99
import itertools
1010
import logging
11+
import inspect
1112
from signal import signal, default_int_handler, SIGINT
1213
import sys
1314
import time
@@ -237,7 +238,9 @@ async def process_control(self, msg):
237238
self.log.error("UNKNOWN CONTROL MESSAGE TYPE: %r", msg_type)
238239
else:
239240
try:
240-
await handler(self.control_stream, idents, msg)
241+
result = handler(self.control_stream, idents, msg)
242+
if inspect.isawaitable(result):
243+
await result
241244
except Exception:
242245
self.log.error("Exception in control handler:", exc_info=True)
243246

@@ -303,7 +306,9 @@ async def dispatch_shell(self, msg):
303306
except Exception:
304307
self.log.debug("Unable to signal in pre_handler_hook:", exc_info=True)
305308
try:
306-
await handler(self.shell_stream, idents, msg)
309+
result = handler(self.shell_stream, idents, msg)
310+
if inspect.isawaitable(result):
311+
await result
307312
except Exception:
308313
self.log.error("Exception in message handler:", exc_info=True)
309314
finally:

0 commit comments

Comments
 (0)