Skip to content

Commit

Permalink
Merge pull request #338 from kevin-bates/fix-maybe-future
Browse files Browse the repository at this point in the history
Use appropriate maybe-future to handle asyncio futures
  • Loading branch information
kevin-bates authored Aug 10, 2020
2 parents 6936a3d + 90b4834 commit b4c8632
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ dist: xenial # required for Python >= 3.7
sudo: false
language: python
python:
- 2.7
- 3.4
- 3.5
- 3.6
- 3.7
- 3.8

env:
- ASYNC_TEST_TIMEOUT=10
Expand Down
3 changes: 2 additions & 1 deletion kernel_gateway/services/kernels/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from functools import partial
from tornado import gen, ioloop
from notebook.services.kernels.kernelmanager import MappingKernelManager
from notebook.utils import maybe_future
from jupyter_client.ioloop import IOLoopKernelManager

class SeedingMappingKernelManager(MappingKernelManager):
Expand Down Expand Up @@ -78,7 +79,7 @@ def start_kernel(self, *args, **kwargs):
"""
if self.parent.force_kernel_name:
kwargs['kernel_name'] = self.parent.force_kernel_name
kernel_id = yield gen.maybe_future(super(SeedingMappingKernelManager, self).start_kernel(*args, **kwargs))
kernel_id = yield 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 Down
7 changes: 3 additions & 4 deletions kernel_gateway/services/sessions/sessionmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""Session manager that keeps all its metadata in memory."""

import uuid
from notebook.utils import maybe_future
from tornado import web, gen
from traitlets.config.configurable import LoggingConfigurable
from ipython_genutils.py3compat import unicode_type
Expand Down Expand Up @@ -71,10 +72,8 @@ def create_session(self, path=None, kernel_name=None, kernel_id=None, *args, **k
"""
session_id = self.new_session_id()
# allow nbm to specify kernels cwd
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))
kernel_id = yield 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, *args, **kwargs):
"""Saves the metadata for the session with the given `session_id`.
Expand Down

0 comments on commit b4c8632

Please sign in to comment.