Skip to content

Commit

Permalink
Merge pull request #494 from davidbrochart/fix_async
Browse files Browse the repository at this point in the history
KernelManager.post_start_kernel is async in jupyter_client>=7.0
  • Loading branch information
ccordoba12 committed Aug 3, 2021
2 parents a97fe51 + 6994ebd commit 80481f8
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions qtconsole/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Local imports
from traitlets import Bool, DottedObjectName

import jupyter_client
from jupyter_client import KernelManager
from jupyter_client.restarter import KernelRestarter

Expand All @@ -27,6 +28,25 @@ def poll(self):
super().poll()


def _post_start_kernel():
# KernelManager.post_start_kernel is async in jupyter_client>=7.0
if int(jupyter_client.__version__.split(".")[0]) >= 7:
async def post_start_kernel(self, **kw):
"""Kernel restarted."""
await super(QtKernelManager, self).post_start_kernel(**kw)
if self._is_restarting:
self.kernel_restarted.emit()
self._is_restarting = False
else:
def post_start_kernel(self, **kw):
"""Kernel restarted."""
super(QtKernelManager, self).post_start_kernel(**kw)
if self._is_restarting:
self.kernel_restarted.emit()
self._is_restarting = False
return post_start_kernel


class QtKernelManager(KernelManager, QtKernelManagerMixin):
"""A KernelManager with Qt signals for restart"""

Expand Down Expand Up @@ -55,12 +75,7 @@ def stop_restarter(self):
if self._restarter is not None:
self._restarter.stop()

def post_start_kernel(self, **kw):
"""Kernel restarted."""
super().post_start_kernel(**kw)
if self._is_restarting:
self.kernel_restarted.emit()
self._is_restarting = False
post_start_kernel = _post_start_kernel()

def _handle_kernel_restarting(self):
"""Kernel has died, and will be restarted."""
Expand Down

0 comments on commit 80481f8

Please sign in to comment.