From 1b5b60357a56ed009be212ea17c09dcd878d14d9 Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 6 Mar 2019 10:46:00 +0100 Subject: [PATCH 1/4] Merge pull request #4449 from minrk/unpin-tornado tornado 6 compatibility --- .travis.yml | 10 ++++++-- docs/source/changelog.rst | 9 +++++++ notebook/base/zmqhandlers.py | 4 +-- notebook/utils.py | 48 ++++++++++++++++++++++++++++++++++++ setup.py | 2 +- 5 files changed, 68 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index e16c5a8d4c..82052a20c7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,7 +49,8 @@ before_install: fi install: - - pip install --pre .[test] + - pip install --pre .[test] $EXTRA_PIP + - pip freeze - 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 @@ -96,10 +97,15 @@ matrix: env: GROUP=python - python: 3.5 env: GROUP=python - - python: "3.7-dev" + - python: 3.7 + dist: xenial env: GROUP=python - python: 3.6 env: GROUP=docs + - python: 3.6 + env: + - GROUP=python + - EXTRA_PIP="tornado<5" after_success: - codecov diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index 9ca8b65b9b..59c534546a 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -21,6 +21,15 @@ We strongly recommend that you upgrade pip to version 9+ of pip before upgrading Use ``pip install pip --upgrade`` to upgrade pip. Check pip version with ``pip --version``. +.. _release-5.7.5: + +5.7.5 +----- + +- Fix compatibility with tornado 6 (:ghpull:`4392`, :ghpull:`4449`). +- Fix opening integer filedescriptor during startup on Python 2 (:ghpull:`4349`) +- Fix compatibility with asynchronous `KernelManager.restart_kernel` methods (:ghpull:`4412`) + .. _release-5.7.4: 5.7.4 diff --git a/notebook/base/zmqhandlers.py b/notebook/base/zmqhandlers.py index 19b5bbb29f..943dbaed46 100644 --- a/notebook/base/zmqhandlers.py +++ b/notebook/base/zmqhandlers.py @@ -172,7 +172,7 @@ def open(self, *args, **kwargs): def send_ping(self): """send a ping to keep the websocket alive""" - if self.stream.closed() and self.ping_callback is not None: + if self.ws_connection is None and self.ping_callback is not None: self.ping_callback.stop() return @@ -237,7 +237,7 @@ def _reserialize_reply(self, msg_or_list, channel=None): def _on_zmq_reply(self, stream, msg_list): # Sometimes this gets triggered when the on_close method is scheduled in the # eventloop but hasn't been called. - if self.stream.closed() or stream.closed(): + if self.ws_connection is None or stream.closed(): self.log.warning("zmq message arrived on closed channel") self.close() return diff --git a/notebook/utils.py b/notebook/utils.py index 5b3d9dff9a..918e198829 100644 --- a/notebook/utils.py +++ b/notebook/utils.py @@ -12,6 +12,20 @@ import sys from distutils.version import LooseVersion +try: + from inspect import isawaitable +except ImportError: + def isawaitable(f): + """If isawaitable is undefined, nothing is awaitable""" + return False + +try: + from concurrent.futures import Future as ConcurrentFuture +except ImportError: + class ConcurrentFuture: + """If concurrent.futures isn't importable, nothing will be a c.f.Future""" + pass + try: from urllib.parse import quote, unquote, urlparse, urljoin from urllib.request import pathname2url @@ -19,6 +33,10 @@ from urllib import quote, unquote, pathname2url from urlparse import urlparse, urljoin +# tornado.concurrent.Future is asyncio.Future +# in tornado >=5 with Python 3 +from tornado.concurrent import Future as TornadoFuture +from tornado import gen from ipython_genutils import py3compat # UF_HIDDEN is a stat flag not defined in the stat module. @@ -306,3 +324,33 @@ def _check_pid_posix(pid): check_pid = _check_pid_win32 else: check_pid = _check_pid_posix + + +def maybe_future(obj): + """Like tornado's gen.maybe_future + + but more compatible with asyncio for recent versions + of tornado + """ + if isinstance(obj, TornadoFuture): + return obj + elif isawaitable(obj): + return asyncio.ensure_future(obj) + elif isinstance(obj, ConcurrentFuture): + return asyncio.wrap_future(obj) + else: + # not awaitable, wrap scalar in future + f = TornadoFuture() + f.set_result(obj) + return f + +# monkeypatch tornado gen.maybe_future +# on Python 3 +# TODO: remove monkeypatch after backporting smaller fix to 5.x +try: + import asyncio +except ImportError: + pass +else: + import tornado.gen + tornado.gen.maybe_future = maybe_future diff --git a/setup.py b/setup.py index 51d06c042c..15e027a73a 100755 --- a/setup.py +++ b/setup.py @@ -79,7 +79,7 @@ zip_safe = False, install_requires = [ 'jinja2', - 'tornado>=4, <6', + 'tornado>=4.1', # pyzmq>=17 is not technically necessary, # but hopefully avoids incompatibilities with Tornado 5. April 2018 'pyzmq>=17', From 667b459070afe83f961b746dd71e2f578aa6e33d Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 6 Mar 2019 10:51:51 +0100 Subject: [PATCH 2/4] pin tornado<7 since this is 5.7.x, assume tornado 7 will break it 6.0 will not have a similar pin --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 15e027a73a..e38f43b13e 100755 --- a/setup.py +++ b/setup.py @@ -79,7 +79,7 @@ zip_safe = False, install_requires = [ 'jinja2', - 'tornado>=4.1', + 'tornado>=4.1,<7', # pyzmq>=17 is not technically necessary, # but hopefully avoids incompatibilities with Tornado 5. April 2018 'pyzmq>=17', From 8244468dc32d26e4a98fd2fccf87a54cb9ed0c10 Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 6 Mar 2019 10:52:02 +0100 Subject: [PATCH 3/4] test py27 with tornado 4 on travis --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 82052a20c7..5ed2ce9497 100644 --- a/.travis.yml +++ b/.travis.yml @@ -106,6 +106,10 @@ matrix: env: - GROUP=python - EXTRA_PIP="tornado<5" + - python: 2.7 + env: + - GROUP=python + - EXTRA_PIP="tornado<5" after_success: - codecov From d1e8d4df6c25075e0b020aa081b5041e89835fca Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 6 Mar 2019 10:58:43 +0100 Subject: [PATCH 4/4] release 5.7.5 --- notebook/_version.py | 2 +- notebook/static/base/js/namespace.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/notebook/_version.py b/notebook/_version.py index 22f5e30b2f..ca3ef38300 100644 --- a/notebook/_version.py +++ b/notebook/_version.py @@ -9,5 +9,5 @@ # Next beta/alpha/rc release: The version number for beta is X.Y.ZbN **without dots**. -version_info = (5, 7, 5, '.dev0') +version_info = (5, 7, 5) __version__ = '.'.join(map(str, version_info[:3])) + ''.join(version_info[3:]) diff --git a/notebook/static/base/js/namespace.js b/notebook/static/base/js/namespace.js index 4d853682cd..ba194f5763 100644 --- a/notebook/static/base/js/namespace.js +++ b/notebook/static/base/js/namespace.js @@ -73,7 +73,7 @@ define(function(){ // tree jglobal('SessionList','tree/js/sessionlist'); - Jupyter.version = "5.7.5.dev0"; + Jupyter.version = "5.7.5"; Jupyter._target = '_blank'; return Jupyter; });