def initialize(self, test):
self._OPENID_ENDPOINT = test.get_url('/openid/server/authenticate')
- @asynchronous
- def get(self):
- if self.get_argument('openid.mode', None):
- with warnings.catch_warnings():
- warnings.simplefilter('ignore', DeprecationWarning)
- self.get_authenticated_user(
- self.on_user, http_client=self.settings['http_client'])
- return
- res = self.authenticate_redirect()
- assert isinstance(res, Future)
- assert res.done()
+ with ignore_deprecation():
+ @asynchronous
+ def get(self):
+ if self.get_argument('openid.mode', None):
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', DeprecationWarning)
+ self.get_authenticated_user(
+ self.on_user, http_client=self.settings['http_client'])
+ return
+ res = self.authenticate_redirect()
+ assert isinstance(res, Future)
+ assert res.done()
def on_user(self, user):
if user is None:
def _oauth_consumer_token(self):
return dict(key='asdf', secret='qwer')
- @asynchronous
- def get(self):
- if self.get_argument('oauth_token', None):
- with warnings.catch_warnings():
- warnings.simplefilter('ignore', DeprecationWarning)
- self.get_authenticated_user(
- self.on_user, http_client=self.settings['http_client'])
- return
- res = self.authorize_redirect(http_client=self.settings['http_client'])
- assert isinstance(res, Future)
+ with ignore_deprecation():
+ @asynchronous
+ def get(self):
+ if self.get_argument('oauth_token', None):
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', DeprecationWarning)
+ self.get_authenticated_user(
+ self.on_user, http_client=self.settings['http_client'])
+ return
+ res = self.authorize_redirect(http_client=self.settings['http_client'])
+ assert isinstance(res, Future)
def on_user(self, user):
if user is None:
class TwitterClientLoginHandlerLegacy(TwitterClientHandler):
- @asynchronous
- def get(self):
- if self.get_argument("oauth_token", None):
- self.get_authenticated_user(self.on_user)
- return
- self.authorize_redirect()
+ with ignore_deprecation():
+ @asynchronous
+ def get(self):
+ if self.get_argument("oauth_token", None):
+ self.get_authenticated_user(self.on_user)
+ return
+ self.authorize_redirect()
def on_user(self, user):
if user is None:
class GenCoroutineUnfinishedSequenceHandler(RequestHandler):
- @asynchronous
@gen.coroutine
def get(self):
yield gen.moment
from tornado.simple_httpclient import SimpleAsyncHTTPClient
from tornado.testing import AsyncHTTPTestCase, AsyncHTTPSTestCase, AsyncTestCase, ExpectLog, gen_test # noqa: E501
from tornado.test.util import unittest, skipOnTravis, ignore_deprecation
-from tornado.web import Application, RequestHandler, asynchronous, stream_request_body
+from tornado.web import Application, RequestHandler, stream_request_body
from contextlib import closing
import datetime
self.write(''.join(chr(i % 256) * 1024 for i in range(512)))
class FinishOnCloseHandler(RequestHandler):
- @asynchronous
+ @gen.coroutine
def get(self):
self.flush()
+ never_finish = Event()
+ yield never_finish.wait()
def on_connection_close(self):
# This is not very realistic, but finishing the request
from tornado.httputil import HTTPHeaders, ResponseStartLine
from tornado.ioloop import IOLoop
from tornado.iostream import UnsatisfiableReadError
+from tornado.locks import Event
from tornado.log import gen_log
from tornado.concurrent import Future
from tornado.netutil import Resolver, bind_sockets
ExpectLog, gen_test)
from tornado.test.util import (skipOnTravis, skipIfNoIPv6, refusing_port, skipBefore35,
exec_test, ignore_deprecation)
-from tornado.web import RequestHandler, Application, asynchronous, url, stream_request_body
+from tornado.web import RequestHandler, Application, url, stream_request_body
class SimpleHTTPClientCommonTestCase(httpclient_test.HTTPClientCommonTestCase):
self.queue = queue
self.wake_callback = wake_callback
- @asynchronous
+ @gen.coroutine
def get(self):
logging.debug("queuing trigger")
self.queue.append(self.finish)
if self.get_argument("wake", "true") == "true":
self.wake_callback()
+ never_finish = Event()
+ yield never_finish.wait()
class HangHandler(RequestHandler):
- @asynchronous
+ @gen.coroutine
def get(self):
- pass
+ never_finish = Event()
+ yield never_finish.wait()
class ContentLengthHandler(RequestHandler):
def __init__(self, app, request):
super(TestRequestHandler, self).__init__(app, request)
- @asynchronous
- def get(self):
- logging.debug('in get()')
- # call self.part2 without a self.async_callback wrapper. Its
- # exception should still get thrown
- IOLoop.current().add_callback(self.part2)
+ with ignore_deprecation():
+ @asynchronous
+ def get(self):
+ logging.debug('in get()')
+ # call self.part2 without a self.async_callback wrapper. Its
+ # exception should still get thrown
+ IOLoop.current().add_callback(self.part2)
def part2(self):
logging.debug('in part2()')
from tornado.ioloop import IOLoop
from tornado.iostream import IOStream
from tornado import locale
+from tornado.locks import Event
from tornado.log import app_log, gen_log
from tornado.simple_httpclient import SimpleAsyncHTTPClient
from tornado.template import DictLoader
def initialize(self, test):
self.test = test
- @asynchronous
+ @gen.coroutine
def get(self):
self.test.on_handler_waiting()
+ never_finish = Event()
+ yield never_finish.wait()
def on_connection_close(self):
self.test.on_connection_close()
class FlowControlHandler(RequestHandler):
# These writes are too small to demonstrate real flow control,
# but at least it shows that the callbacks get run.
- @asynchronous
- def get(self):
- self.write("1")
- self.flush(callback=self.step2)
+ with ignore_deprecation():
+ @asynchronous
+ def get(self):
+ self.write("1")
+ self.flush(callback=self.step2)
def step2(self):
self.write("2")
class Handler(RequestHandler):
exc_count = 0
- @asynchronous
- def get(self):
- IOLoop.current().add_callback(lambda: 1 / 0)
- IOLoop.current().add_callback(lambda: 1 / 0)
+ with ignore_deprecation():
+ @asynchronous
+ def get(self):
+ IOLoop.current().add_callback(lambda: 1 / 0)
+ IOLoop.current().add_callback(lambda: 1 / 0)
def log_exception(self, typ, value, tb):
MultipleExceptionTest.Handler.exc_count += 1
import tornado
import traceback
import types
+import warnings
from inspect import isclass
from io import BytesIO
.. versionchanged:: 4.3 Returning anything but ``None`` or a
yieldable object from a method decorated with ``@asynchronous``
is an error. Such return values were previously ignored silently.
+
+ .. deprecated:: 5.1
+
+ This decorator is deprecated and will be removed in Tornado 6.0.
+ Use coroutines instead.
"""
+ warnings.warn("@asynchronous is deprecated, use coroutines instead",
+ DeprecationWarning)
# Delay the IOLoop import because it's not available on app engine.
from tornado.ioloop import IOLoop