Skip to content

Commit

Permalink
Merge pull request #304 from minrk/tornado-5
Browse files Browse the repository at this point in the history
prepare for tornado 5
  • Loading branch information
takluyver authored Nov 13, 2017
2 parents 2822872 + 6674afa commit 7a0278a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 36 deletions.
20 changes: 4 additions & 16 deletions jupyter_client/ioloop/manager.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
"""A kernel manager with a tornado IOLoop"""

#-----------------------------------------------------------------------------
# Copyright (c) The Jupyter Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

from __future__ import absolute_import

Expand All @@ -24,10 +16,6 @@
from jupyter_client.manager import KernelManager
from .restarter import IOLoopKernelRestarter

#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------


def as_zmqstream(f):
def wrapped(self, *args, **kwargs):
Expand All @@ -37,9 +25,9 @@ def wrapped(self, *args, **kwargs):

class IOLoopKernelManager(KernelManager):

loop = Instance('zmq.eventloop.ioloop.IOLoop')
loop = Instance('tornado.ioloop.IOLoop')
def _loop_default(self):
return ioloop.IOLoop.instance()
return ioloop.IOLoop.current()

restarter_class = Type(
default_value=IOLoopKernelRestarter,
Expand Down
27 changes: 9 additions & 18 deletions jupyter_client/ioloop/restarter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,36 @@
restarts the kernel if it dies.
"""

#-----------------------------------------------------------------------------
# Copyright (c) The Jupyter Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

from __future__ import absolute_import
import warnings

from zmq.eventloop import ioloop


from jupyter_client.restarter import KernelRestarter
from traitlets import (
Instance,
)

#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------

class IOLoopKernelRestarter(KernelRestarter):
"""Monitor and autorestart a kernel."""

loop = Instance('zmq.eventloop.ioloop.IOLoop')
loop = Instance('tornado.ioloop.IOLoop')
def _loop_default(self):
return ioloop.IOLoop.instance()
warnings.warn("IOLoopKernelRestarter.loop is deprecated in jupyter-client 5.2",
DeprecationWarning, stacklevel=4,
)
return ioloop.IOLoop.current()

_pcallback = None

def start(self):
"""Start the polling of the kernel."""
if self._pcallback is None:
self._pcallback = ioloop.PeriodicCallback(
self.poll, 1000*self.time_to_dead, self.loop
self.poll, 1000*self.time_to_dead,
)
self._pcallback.start()

Expand Down
4 changes: 2 additions & 2 deletions jupyter_client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ def _context_default(self):
session = Instance('jupyter_client.session.Session',
allow_none=True)

loop = Instance('zmq.eventloop.ioloop.IOLoop')
loop = Instance('tornado.ioloop.IOLoop')
def _loop_default(self):
return IOLoop.instance()
return IOLoop.current()

def __init__(self, **kwargs):
super(SessionFactory, self).__init__(**kwargs)
Expand Down
12 changes: 12 additions & 0 deletions jupyter_client/tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import sys
import uuid
from datetime import datetime
try:
from unittest import mock
except ImportError:
import mock

import pytest

Expand All @@ -34,6 +38,14 @@ def setUp(self):
self.session = ss.Session()


@pytest.fixture
def no_copy_threshold():
"""Disable zero-copy optimizations in pyzmq >= 17"""
with mock.patch.object(zmq, 'COPY_THRESHOLD', 1):
yield


@pytest.mark.usefixtures('no_copy_threshold')
class TestSession(SessionTestCase):

def test_msg(self):
Expand Down

0 comments on commit 7a0278a

Please sign in to comment.