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.
This commit is contained in:
Andrew Rabert 2018-11-26 16:54:34 -05:00 committed by Andrew Rabert
parent 8dfb33d6cc
commit 234fb6d479
5 changed files with 11 additions and 68 deletions

View file

@ -1 +1 @@
tornado>=3.1,<6
tornado>=5,<6

View file

@ -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)

View file

@ -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):

View file

@ -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)

20
tox.ini
View file

@ -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}