|
8 | 8 | from functools import partial |
9 | 9 | import itertools |
10 | 10 | import logging |
| 11 | +import inspect |
11 | 12 | from signal import signal, default_int_handler, SIGINT |
12 | 13 | import sys |
13 | 14 | import time |
@@ -237,7 +238,14 @@ async def process_control(self, msg): |
237 | 238 | self.log.error("UNKNOWN CONTROL MESSAGE TYPE: %r", msg_type) |
238 | 239 | else: |
239 | 240 | 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 |
| 244 | + else: |
| 245 | + warnings.warn( |
| 246 | + "Message handlers should be awaitable", |
| 247 | + DeprecationWarning, |
| 248 | + stacklevel=2) |
241 | 249 | except Exception: |
242 | 250 | self.log.error("Exception in control handler:", exc_info=True) |
243 | 251 |
|
@@ -304,7 +312,14 @@ async def dispatch_shell(self, msg): |
304 | 312 | except Exception: |
305 | 313 | self.log.debug("Unable to signal in pre_handler_hook:", exc_info=True) |
306 | 314 | try: |
307 | | - await handler(self.shell_stream, idents, msg) |
| 315 | + result = handler(self.shell_stream, idents, msg) |
| 316 | + if inspect.isawaitable(result): |
| 317 | + await result |
| 318 | + else: |
| 319 | + warnings.warn( |
| 320 | + "Message handlers should be awaitable", |
| 321 | + DeprecationWarning, |
| 322 | + stacklevel=2) |
308 | 323 | except Exception: |
309 | 324 | self.log.error("Exception in message handler:", exc_info=True) |
310 | 325 | finally: |
|
0 commit comments