Skip to content

Commit e2ac757

Browse files
authored
Merge pull request #4449 from minrk/unpin-tornado
tornado 6 compatibility
2 parents ff238cc + 0b73ab6 commit e2ac757

File tree

6 files changed

+71
-8
lines changed

6 files changed

+71
-8
lines changed

.travis.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ before_install:
5050
- pip install "attrs>=17.4.0"
5151

5252
install:
53-
- pip install --pre .[test]
53+
- pip install --pre .[test] $EXTRA_PIP
54+
- pip freeze
5455
- 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
5556

5657

@@ -97,10 +98,15 @@ matrix:
9798
env: GROUP=python
9899
- python: 3.5
99100
env: GROUP=python
100-
- python: "3.7-dev"
101+
- python: 3.7
102+
dist: xenial
101103
env: GROUP=python
102104
- python: 3.6
103105
env: GROUP=docs
106+
- python: 3.6
107+
env:
108+
- GROUP=python
109+
- EXTRA_PIP="tornado<5"
104110

105111
after_success:
106112
- 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/gateway/managers.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from tornado import gen, web
99
from tornado.escape import json_encode, json_decode, url_escape
1010
from tornado.httpclient import HTTPClient, AsyncHTTPClient, HTTPError
11-
from tornado.simple_httpclient import HTTPTimeoutError
1211

1312
from ..services.kernels.kernelmanager import MappingKernelManager
1413
from ..services.sessions.sessionmanager import SessionManager
@@ -259,9 +258,9 @@ def gateway_request(endpoint, **kwargs):
259258
except ConnectionRefusedError:
260259
raise web.HTTPError(503, "Connection refused from Gateway server url '{}'. "
261260
"Check to be sure the Gateway instance is running.".format(GatewayClient.instance().url))
262-
except HTTPTimeoutError:
261+
except HTTPError:
263262
# This can occur if the host is valid (e.g., foo.com) but there's nothing there.
264-
raise web.HTTPError(504, "Timeout error attempting to connect to Gateway server url '{}'. " \
263+
raise web.HTTPError(504, "Error attempting to connect to Gateway server url '{}'. " \
265264
"Ensure gateway url is valid and the Gateway instance is running.".format(
266265
GatewayClient.instance().url))
267266
except gaierror as e:

notebook/utils.py

+49
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,34 @@ 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
357+

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
zip_safe = False,
9999
install_requires = [
100100
'jinja2',
101-
'tornado>=4, <6',
101+
'tornado>=4.1',
102102
# pyzmq>=17 is not technically necessary,
103103
# but hopefully avoids incompatibilities with Tornado 5. April 2018
104104
'pyzmq>=17',

0 commit comments

Comments
 (0)