Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepare for tornado 5 #304

Merged
merged 2 commits into from Nov 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 4 additions & 16 deletions jupyter_client/ioloop/manager.py
@@ -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
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
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
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