Skip to content

Commit 1b5b603

Browse files
committed
Merge pull request jupyter#4449 from minrk/unpin-tornado
tornado 6 compatibility
1 parent ab64452 commit 1b5b603

File tree

5 files changed

+68
-5
lines changed

5 files changed

+68
-5
lines changed

.travis.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ before_install:
4949
fi
5050
5151
install:
52-
- pip install --pre .[test]
52+
- pip install --pre .[test] $EXTRA_PIP
53+
- pip freeze
5354
- wget https://github.com/jgm/pandoc/releases/download/1.19.1/pandoc-1.19.1-1-amd64.deb && sudo dpkg -i pandoc-1.19.1-1-amd64.deb
5455

5556

@@ -96,10 +97,15 @@ matrix:
9697
env: GROUP=python
9798
- python: 3.5
9899
env: GROUP=python
99-
- python: "3.7-dev"
100+
- python: 3.7
101+
dist: xenial
100102
env: GROUP=python
101103
- python: 3.6
102104
env: GROUP=docs
105+
- python: 3.6
106+
env:
107+
- GROUP=python
108+
- EXTRA_PIP="tornado<5"
103109

104110
after_success:
105111
- codecov

docs/source/changelog.rst

+9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ We strongly recommend that you upgrade pip to version 9+ of pip before upgrading
2121
Use ``pip install pip --upgrade`` to upgrade pip. Check pip version with
2222
``pip --version``.
2323

24+
.. _release-5.7.5:
25+
26+
5.7.5
27+
-----
28+
29+
- Fix compatibility with tornado 6 (:ghpull:`4392`, :ghpull:`4449`).
30+
- Fix opening integer filedescriptor during startup on Python 2 (:ghpull:`4349`)
31+
- Fix compatibility with asynchronous `KernelManager.restart_kernel` methods (:ghpull:`4412`)
32+
2433
.. _release-5.7.4:
2534

2635
5.7.4

notebook/base/zmqhandlers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def open(self, *args, **kwargs):
172172

173173
def send_ping(self):
174174
"""send a ping to keep the websocket alive"""
175-
if self.stream.closed() and self.ping_callback is not None:
175+
if self.ws_connection is None and self.ping_callback is not None:
176176
self.ping_callback.stop()
177177
return
178178

@@ -237,7 +237,7 @@ def _reserialize_reply(self, msg_or_list, channel=None):
237237
def _on_zmq_reply(self, stream, msg_list):
238238
# Sometimes this gets triggered when the on_close method is scheduled in the
239239
# eventloop but hasn't been called.
240-
if self.stream.closed() or stream.closed():
240+
if self.ws_connection is None or stream.closed():
241241
self.log.warning("zmq message arrived on closed channel")
242242
self.close()
243243
return

notebook/utils.py

+48
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,31 @@
1212
import sys
1313
from distutils.version import LooseVersion
1414

15+
try:
16+
from inspect import isawaitable
17+
except ImportError:
18+
def isawaitable(f):
19+
"""If isawaitable is undefined, nothing is awaitable"""
20+
return False
21+
22+
try:
23+
from concurrent.futures import Future as ConcurrentFuture
24+
except ImportError:
25+
class ConcurrentFuture:
26+
"""If concurrent.futures isn't importable, nothing will be a c.f.Future"""
27+
pass
28+
1529
try:
1630
from urllib.parse import quote, unquote, urlparse, urljoin
1731
from urllib.request import pathname2url
1832
except ImportError:
1933
from urllib import quote, unquote, pathname2url
2034
from urlparse import urlparse, urljoin
2135

36+
# tornado.concurrent.Future is asyncio.Future
37+
# in tornado >=5 with Python 3
38+
from tornado.concurrent import Future as TornadoFuture
39+
from tornado import gen
2240
from ipython_genutils import py3compat
2341

2442
# UF_HIDDEN is a stat flag not defined in the stat module.
@@ -306,3 +324,33 @@ def _check_pid_posix(pid):
306324
check_pid = _check_pid_win32
307325
else:
308326
check_pid = _check_pid_posix
327+
328+
329+
def maybe_future(obj):
330+
"""Like tornado's gen.maybe_future
331+
332+
but more compatible with asyncio for recent versions
333+
of tornado
334+
"""
335+
if isinstance(obj, TornadoFuture):
336+
return obj
337+
elif isawaitable(obj):
338+
return asyncio.ensure_future(obj)
339+
elif isinstance(obj, ConcurrentFuture):
340+
return asyncio.wrap_future(obj)
341+
else:
342+
# not awaitable, wrap scalar in future
343+
f = TornadoFuture()
344+
f.set_result(obj)
345+
return f
346+
347+
# monkeypatch tornado gen.maybe_future
348+
# on Python 3
349+
# TODO: remove monkeypatch after backporting smaller fix to 5.x
350+
try:
351+
import asyncio
352+
except ImportError:
353+
pass
354+
else:
355+
import tornado.gen
356+
tornado.gen.maybe_future = maybe_future

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
zip_safe = False,
8080
install_requires = [
8181
'jinja2',
82-
'tornado>=4, <6',
82+
'tornado>=4.1',
8383
# pyzmq>=17 is not technically necessary,
8484
# but hopefully avoids incompatibilities with Tornado 5. April 2018
8585
'pyzmq>=17',

0 commit comments

Comments
 (0)