Skip to content

Commit

Permalink
Merge pull request #141 from parente/fix-super-call
Browse files Browse the repository at this point in the history
Fix call to super in kernel manager
  • Loading branch information
minrk committed Apr 1, 2016
2 parents 80962ea + fad82e3 commit ec87f88
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
8 changes: 5 additions & 3 deletions kernel_gateway/services/kernels/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

import json
import tornado
import notebook.services.kernels.handlers as notebook_handlers
from tornado import gen
from functools import partial
from datetime import datetime
import notebook.services.kernels.handlers as notebook_handlers
from ...mixins import TokenAuthorizationMixin, CORSMixin, JSONErrorsMixin
from ...services.activity.manager import (LAST_MESSAGE_TO_CLIENT,
LAST_MESSAGE_TO_KERNEL, LAST_TIME_STATE_CHANGED, BUSY, CONNECTIONS,
Expand All @@ -19,6 +20,7 @@ class MainKernelHandler(TokenAuthorizationMixin,
"""Extends the notebook main kernel handler with token auth, CORS, and
JSON errors.
"""
@gen.coroutine
def post(self):
"""Overrides the super class method to honor the max number of allowed
kernels configuration setting and to support custom kernel environment
Expand Down Expand Up @@ -52,11 +54,11 @@ def post(self):
orig_start = self.kernel_manager.start_kernel
self.kernel_manager.start_kernel = partial(self.kernel_manager.start_kernel, env=env)
try:
super(MainKernelHandler, self).post()
yield super(MainKernelHandler, self).post()
finally:
self.kernel_manager.start_kernel = orig_start
else:
super(MainKernelHandler, self).post()
yield super(MainKernelHandler, self).post()

def get(self):
"""Overrides the super class method to honor the kernel listing
Expand Down
6 changes: 4 additions & 2 deletions kernel_gateway/services/kernels/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Distributed under the terms of the Modified BSD License.
"""Kernel manager that optionally seeds kernel memory."""

from tornado import gen
from notebook.services.kernels.kernelmanager import MappingKernelManager
from jupyter_client.ioloop import IOLoopKernelManager
from ..cell.parser import APICellParser
Expand Down Expand Up @@ -62,11 +63,12 @@ def start_seeded_kernel(self, *args, **kwargs):
"""
self.start_kernel(kernel_name=self.seed_kernelspec, *args, **kwargs)

@gen.coroutine
def start_kernel(self, *args, **kwargs):
"""Starts a kernel and then executes a list of code cells on it if a
seed notebook exists.
"""
kernel_id = super(MappingKernelManager, self).start_kernel(*args, **kwargs)
kernel_id = yield gen.maybe_future(super(SeedingMappingKernelManager, self).start_kernel(*args, **kwargs))

if kernel_id and self.seed_source is not None:
# Only run source if the kernel spec matches the notebook kernel spec
Expand All @@ -92,7 +94,7 @@ def start_kernel(self, *args, **kwargs):
raise RuntimeError('Error seeding kernel memory')
# Shutdown the channels to remove any lingering ZMQ messages
client.stop_channels()
return kernel_id
raise gen.Return(kernel_id)

class KernelGatewayIOLoopKernelManager(IOLoopKernelManager):
"""Extends the IOLoopKernelManager used by the SeedingMappingKernelManager
Expand Down
13 changes: 6 additions & 7 deletions kernel_gateway/services/sessions/sessionmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"""Session manager that keeps all its metadata in memory."""

import uuid

from tornado import web

from tornado import web, gen
from traitlets.config.configurable import LoggingConfigurable
from ipython_genutils.py3compat import unicode_type

Expand Down Expand Up @@ -51,6 +49,7 @@ def new_session_id(self):
"""Creates a uuid for a new session."""
return unicode_type(uuid.uuid4())

@gen.coroutine
def create_session(self, path=None, kernel_name=None):
"""Creates a session and returns its model.
Expand All @@ -70,10 +69,10 @@ def create_session(self, path=None, kernel_name=None):
"""
session_id = self.new_session_id()
# allow nbm to specify kernels cwd
kernel_id = self.kernel_manager.start_kernel(path=path,
kernel_name=kernel_name)
return self.save_session(session_id, path=path,
kernel_id=kernel_id)
kernel_id = yield gen.maybe_future(self.kernel_manager.start_kernel(path=path,
kernel_name=kernel_name))
raise gen.Return(self.save_session(session_id, path=path,
kernel_id=kernel_id))

def save_session(self, session_id, path=None, kernel_id=None):
"""Saves the metadata for the session with the given `session_id`.
Expand Down

0 comments on commit ec87f88

Please sign in to comment.