Skip to content

Commit 97232cd

Browse files
authored
Merge pull request #312 from jupyter/auto-backport-of-pr-304
Backport PR #304 on branch 5.x
2 parents c30d512 + d8087c9 commit 97232cd

File tree

4 files changed

+27
-36
lines changed

4 files changed

+27
-36
lines changed

jupyter_client/ioloop/manager.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
"""A kernel manager with a tornado IOLoop"""
22

3-
#-----------------------------------------------------------------------------
4-
# Copyright (c) The Jupyter Development Team
5-
#
6-
# Distributed under the terms of the BSD License. The full license is in
7-
# the file COPYING, distributed as part of this software.
8-
#-----------------------------------------------------------------------------
9-
10-
#-----------------------------------------------------------------------------
11-
# Imports
12-
#-----------------------------------------------------------------------------
3+
# Copyright (c) Jupyter Development Team.
4+
# Distributed under the terms of the Modified BSD License.
135

146
from __future__ import absolute_import
157

@@ -24,10 +16,6 @@
2416
from jupyter_client.manager import KernelManager
2517
from .restarter import IOLoopKernelRestarter
2618

27-
#-----------------------------------------------------------------------------
28-
# Code
29-
#-----------------------------------------------------------------------------
30-
3119

3220
def as_zmqstream(f):
3321
def wrapped(self, *args, **kwargs):
@@ -37,9 +25,9 @@ def wrapped(self, *args, **kwargs):
3725

3826
class IOLoopKernelManager(KernelManager):
3927

40-
loop = Instance('zmq.eventloop.ioloop.IOLoop')
28+
loop = Instance('tornado.ioloop.IOLoop')
4129
def _loop_default(self):
42-
return ioloop.IOLoop.instance()
30+
return ioloop.IOLoop.current()
4331

4432
restarter_class = Type(
4533
default_value=IOLoopKernelRestarter,

jupyter_client/ioloop/restarter.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,36 @@
44
restarts the kernel if it dies.
55
"""
66

7-
#-----------------------------------------------------------------------------
8-
# Copyright (c) The Jupyter Development Team
9-
#
10-
# Distributed under the terms of the BSD License. The full license is in
11-
# the file COPYING, distributed as part of this software.
12-
#-----------------------------------------------------------------------------
13-
14-
#-----------------------------------------------------------------------------
15-
# Imports
16-
#-----------------------------------------------------------------------------
7+
# Copyright (c) Jupyter Development Team.
8+
# Distributed under the terms of the Modified BSD License.
179

1810
from __future__ import absolute_import
11+
import warnings
1912

2013
from zmq.eventloop import ioloop
2114

22-
2315
from jupyter_client.restarter import KernelRestarter
2416
from traitlets import (
2517
Instance,
2618
)
2719

28-
#-----------------------------------------------------------------------------
29-
# Code
30-
#-----------------------------------------------------------------------------
31-
3220
class IOLoopKernelRestarter(KernelRestarter):
3321
"""Monitor and autorestart a kernel."""
3422

35-
loop = Instance('zmq.eventloop.ioloop.IOLoop')
23+
loop = Instance('tornado.ioloop.IOLoop')
3624
def _loop_default(self):
37-
return ioloop.IOLoop.instance()
25+
warnings.warn("IOLoopKernelRestarter.loop is deprecated in jupyter-client 5.2",
26+
DeprecationWarning, stacklevel=4,
27+
)
28+
return ioloop.IOLoop.current()
3829

3930
_pcallback = None
4031

4132
def start(self):
4233
"""Start the polling of the kernel."""
4334
if self._pcallback is None:
4435
self._pcallback = ioloop.PeriodicCallback(
45-
self.poll, 1000*self.time_to_dead, self.loop
36+
self.poll, 1000*self.time_to_dead,
4637
)
4738
self._pcallback.start()
4839

jupyter_client/session.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ def _context_default(self):
191191
session = Instance('jupyter_client.session.Session',
192192
allow_none=True)
193193

194-
loop = Instance('zmq.eventloop.ioloop.IOLoop')
194+
loop = Instance('tornado.ioloop.IOLoop')
195195
def _loop_default(self):
196-
return IOLoop.instance()
196+
return IOLoop.current()
197197

198198
def __init__(self, **kwargs):
199199
super(SessionFactory, self).__init__(**kwargs)

jupyter_client/tests/test_session.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
import sys
99
import uuid
1010
from datetime import datetime
11+
try:
12+
from unittest import mock
13+
except ImportError:
14+
import mock
1115

1216
import pytest
1317

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

3640

41+
@pytest.fixture
42+
def no_copy_threshold():
43+
"""Disable zero-copy optimizations in pyzmq >= 17"""
44+
with mock.patch.object(zmq, 'COPY_THRESHOLD', 1):
45+
yield
46+
47+
48+
@pytest.mark.usefixtures('no_copy_threshold')
3749
class TestSession(SessionTestCase):
3850

3951
def test_msg(self):

0 commit comments

Comments
 (0)