From 234fb6d479f41e00975d83888178f0f536532427 Mon Sep 17 00:00:00 2001 From: Andrew Rabert Date: Mon, 26 Nov 2018 16:54:34 -0500 Subject: [PATCH] Support only tornado>=5.0 - Drop support for all versions of tornado prior to 5.0. This negates the need for version-aware conditionals that previous existed. - Update tox to test Tornado 5.0 and the unpinned latest version. --- requires/installation.txt | 2 +- sprockets/http/app.py | 18 ++++-------------- sprockets/http/runner.py | 8 +------- tests.py | 31 ------------------------------- tox.ini | 20 +++++--------------- 5 files changed, 11 insertions(+), 68 deletions(-) diff --git a/requires/installation.txt b/requires/installation.txt index e0dcd27..1ab5b32 100644 --- a/requires/installation.txt +++ b/requires/installation.txt @@ -1 +1 @@ -tornado>=3.1,<6 +tornado>=5,<6 diff --git a/sprockets/http/app.py b/sprockets/http/app.py index 54794ec..ba63f57 100644 --- a/sprockets/http/app.py +++ b/sprockets/http/app.py @@ -1,12 +1,8 @@ +import asyncio import logging import sys from tornado import concurrent, web -import tornado - -ASYNCIO_TORNADO = tornado.version_info[0] >= 5 -if ASYNCIO_TORNADO: - import asyncio class _ShutdownHandler(object): @@ -45,18 +41,12 @@ class _ShutdownHandler(object): def _maybe_stop(self): now = self.io_loop.time() - if now < self.__deadline and self._ioloop_has_tasks(): + if now < self.__deadline and asyncio.Task.all_tasks(): self.io_loop.add_timeout(now + 1, self._maybe_stop) else: self.io_loop.stop() self.logger.info('stopped IOLoop') - def _ioloop_has_tasks(self): - if ASYNCIO_TORNADO: - return bool(asyncio.Task.all_tasks()) - else: - return bool(self.io_loop._callbacks or self.io_loop._timeouts) - class CallbackManager(object): """ @@ -131,8 +121,8 @@ class CallbackManager(object): try: maybe_future = callback(self.tornado_application) - if ASYNCIO_TORNADO and asyncio.iscoroutine(maybe_future): - maybe_future = asyncio.create_task(maybe_future) + if asyncio.iscoroutine(maybe_future): + maybe_future = asyncio.create_task(maybe_future) if concurrent.is_future(maybe_future): shutdown.add_future(maybe_future) diff --git a/sprockets/http/runner.py b/sprockets/http/runner.py index 6f008ad..d298d64 100644 --- a/sprockets/http/runner.py +++ b/sprockets/http/runner.py @@ -12,7 +12,6 @@ import signal import sys from tornado import httpserver, ioloop -import tornado import sprockets.http.app @@ -91,12 +90,7 @@ class Runner(object): self.server.listen(port_number) else: self.logger.info('starting processes on port %d', port_number) - if tornado.version_info >= (4, 4): - self.server.bind(port_number, reuse_port=True) - else: - self.logger.warning('port reuse disabled, please upgrade to' - 'at least Tornado 4.4') - self.server.bind(port_number) + self.server.bind(port_number, reuse_port=True) self.server.start(number_of_procs) def stop_server(self): diff --git a/tests.py b/tests.py index 0221508..7a376e6 100644 --- a/tests.py +++ b/tests.py @@ -15,7 +15,6 @@ except ImportError: open_name = '__builtin__.open' from tornado import concurrent, httpserver, httputil, ioloop, testing, web -import tornado import sprockets.http.mixins import sprockets.http.runner @@ -410,8 +409,6 @@ class RunnerTests(MockHelper, unittest.TestCase): self.http_server.start.assert_called_once_with(0) - @unittest.skipUnless(tornado.version_info >= (4, 4), - 'port reuse requries newer tornado') def test_that_production_enables_reuse_port(self): runner = sprockets.http.runner.Runner(self.application) runner.run(8000) @@ -448,34 +445,6 @@ class RunnerTests(MockHelper, unittest.TestCase): self.io_loop.add_callback_from_signal.assert_called_once_with( runner._shutdown) - @unittest.skipUnless(tornado.version_info < (5,), '') - def test_that_shutdown_waits_for_callbacks(self): - def add_timeout(_, callback): - self.io_loop._callbacks.pop() - callback() - self.io_loop.add_timeout = mock.Mock(side_effect=add_timeout) - - self.io_loop._callbacks = [mock.Mock(), mock.Mock()] - runner = sprockets.http.runner.Runner(self.application) - runner.run(8000) - runner._shutdown() - self.io_loop.stop.assert_called_once_with() - self.assertEqual(self.io_loop.add_timeout.call_count, 2) - - @unittest.skipUnless(tornado.version_info < (5,), '') - def test_that_shutdown_waits_for_timeouts(self): - def add_timeout(_, callback): - self.io_loop._timeouts.pop() - callback() - self.io_loop.add_timeout = mock.Mock(side_effect=add_timeout) - - self.io_loop._timeouts = [mock.Mock(), mock.Mock()] - runner = sprockets.http.runner.Runner(self.application) - runner.run(8000) - runner._shutdown() - self.io_loop.stop.assert_called_once_with() - self.assertEqual(self.io_loop.add_timeout.call_count, 2) - def test_that_shutdown_stops_after_timelimit(self): def add_timeout(_, callback): time.sleep(0.1) diff --git a/tox.ini b/tox.ini index 29932de..80f89a0 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py35,py36,py37,tornado42,tornado44,tornado45 +envlist = py35,py36,py37,tornado,tornado50 indexserver = default = https://pypi.python.org/simple toxworkdir = build/tox @@ -13,22 +13,12 @@ commands = deps = -rrequires/testing.txt -[testenv:tornado42] +[testenv:tornado] commands = - {envbindir}/pip install tornado>=4.2,<4.3 + {envbindir}/pip install tornado {[testenv]commands} -[testenv:tornado43] +[testenv:tornado50] commands = - {envbindir}/pip install tornado>=4.3,<4.4 - {[testenv]commands} - -[testenv:tornado44] -commands = - {envbindir}/pip install tornado>=4.4,<4.5 - {[testenv]commands} - -[testenv:tornado45] -commands = - {envbindir}/pip install tornado>=4.5,<4.6 + {envbindir}/pip install tornado=5.0 {[testenv]commands}