Skip to content

Commit

Permalink
Handle synchronous message handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
SylvainCorlay committed Apr 23, 2021
1 parent ee78349 commit 583dc40
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ipykernel/kernelbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from functools import partial
import itertools
import logging
import inspect
from signal import signal, default_int_handler, SIGINT
import sys
import time
Expand Down Expand Up @@ -237,7 +238,9 @@ async def process_control(self, msg):
self.log.error("UNKNOWN CONTROL MESSAGE TYPE: %r", msg_type)
else:
try:
await handler(self.control_stream, idents, msg)
result = handler(self.control_stream, idents, msg)
if inspect.isawaitable(result):
await result
except Exception:
self.log.error("Exception in control handler:", exc_info=True)

Expand Down Expand Up @@ -303,7 +306,9 @@ async def dispatch_shell(self, msg):
except Exception:
self.log.debug("Unable to signal in pre_handler_hook:", exc_info=True)
try:
await handler(self.shell_stream, idents, msg)
result = handler(self.shell_stream, idents, msg)
if inspect.isawaitable(result):
await result
except Exception:
self.log.error("Exception in message handler:", exc_info=True)
finally:
Expand Down

0 comments on commit 583dc40

Please sign in to comment.