What’s new in Tornado 4.1¶
Feb 7, 2015¶
Highlights¶
- If a
Future
contains an exception but that exception is never examined or re-raised (e.g. by yielding theFuture
), a stack trace will be logged when theFuture
is garbage-collected. - New class
tornado.gen.WaitIterator
provides a way to iterate overFutures
in the order they resolve. - The
tornado.websocket
module now supports compression via the “permessage-deflate” extension. OverrideWebSocketHandler.get_compression_options
to enable on the server side, and use thecompression_options
keyword argument towebsocket_connect
on the client side. - When the appropriate packages are installed, it is possible to yield
asyncio.Future
or TwistedDefered
objects in Tornado coroutines.
Backwards-compatibility notes¶
HTTPServer
now callsstart_request
with the correct arguments. This change is backwards-incompatible, afffecting any application which implementedHTTPServerConnectionDelegate
by following the example ofApplication
instead of the documented method signatures.
tornado.curl_httpclient
¶
tornado.curl_httpclient
now supports request bodies forPATCH
and custom methods.tornado.curl_httpclient
now supports resubmitting bodies after following redirects for methods other thanPOST
.curl_httpclient
now runs the streaming and header callbacks on the IOLoop.tornado.curl_httpclient
now uses its own logger for debug output so it can be filtered more easily.
tornado.gen
¶
- New class
tornado.gen.WaitIterator
provides a way to iterate overFutures
in the order they resolve. - When the
singledispatch
library is available (standard on Python 3.4, available viapip install singledispatch
on older versions), theconvert_yielded
function can be used to make other kinds of objects yieldable in coroutines. - New function
tornado.gen.sleep
is a coroutine-friendly analogue totime.sleep
. gen.engine
now correctly captures the stack context for its callbacks.
tornado.httpclient
¶
tornado.httpclient.HTTPRequest
accepts a new argumentraise_error=False
to suppress the default behavior of raising an error for non-200 response codes.
tornado.httpserver
¶
HTTPServer
now callsstart_request
with the correct arguments. This change is backwards-incompatible, afffecting any application which implementedHTTPServerConnectionDelegate
by following the example ofApplication
instead of the documented method signatures.HTTPServer
now tolerates extra newlines which are sometimes inserted between requests on keep-alive connections.HTTPServer
can now use keep-alive connections after a request with a chunked body.HTTPServer
now always reportsHTTP/1.1
instead of echoing the request version.
tornado.httputil
¶
- New function
tornado.httputil.split_host_and_port
for parsing thenetloc
portion of URLs. - The
context
argument toHTTPServerRequest
is now optional, and if a context is supplied theremote_ip
attribute is also optional. HTTPServerRequest.body
is now always a byte string (previously the default empty body would be a unicode string on python 3).- Header parsing now works correctly when newline-like unicode characters are present.
- Header parsing again supports both CRLF and bare LF line separators.
- Malformed
multipart/form-data
bodies will always be logged quietly instead of raising an unhandled exception; previously the behavior was inconsistent depending on the exact error.
tornado.ioloop
¶
- The
kqueue
andselect
IOLoop implementations now report writeability correctly, fixing flow control in IOStream. - When a new
IOLoop
is created, it automatically becomes “current” for the thread if there is not already a current instance. - New method
PeriodicCallback.is_running
can be used to see whether thePeriodicCallback
has been started.
tornado.iostream
¶
IOStream.start_tls
now uses theserver_hostname
parameter for certificate validation.SSLIOStream
will no longer consume 100% CPU after certain error conditions.SSLIOStream
no longer logsEBADF
errors during the handshake as they can result from nmap scans in certain modes.
tornado.options
¶
parse_config_file
now always decodes the config file as utf8 on Python 3.tornado.options.define
more accurately finds the module defining the option.
tornado.platform.asyncio
¶
- It is now possible to yield
asyncio.Future
objects in coroutines when thesingledispatch
library is available andtornado.platform.asyncio
has been imported. - New methods
tornado.platform.asyncio.to_tornado_future
andto_asyncio_future
convert between the two libraries’Future
classes.
tornado.platform.twisted
¶
- It is now possible to yield
Deferred
objects in coroutines when thesingledispatch
library is available andtornado.platform.twisted
has been imported.
tornado.tcpclient
¶
TCPClient
will no longer raise an exception due to an ill-timed timeout.
tornado.tcpserver
¶
TCPServer
no longer ignores itsread_chunk_size
argument.
tornado.testing
¶
AsyncTestCase
has better support for multiple exceptions. Previously it would silently swallow all but the last; now it raises the first and logs all the rest.AsyncTestCase
now cleans upSubprocess
state ontearDown
when necessary.
tornado.web
¶
- The
asynchronous
decorator now understandsconcurrent.futures.Future
in addition totornado.concurrent.Future
. StaticFileHandler
no longer logs a stack trace if the connection is closed while sending the file.RequestHandler.send_error
now supports areason
keyword argument, similar totornado.web.HTTPError
.RequestHandler.locale
now has a property setter.Application.add_handlers
hostname matching now works correctly with IPv6 literals.- Redirects for the
Application
default_host
setting now match the request protocol instead of redirecting HTTPS to HTTP. - Malformed
_xsrf
cookies are now ignored instead of causing uncaught exceptions. Application.start_request
now has the same signature asHTTPServerConnectionDelegate.start_request
.
tornado.websocket
¶
- The
tornado.websocket
module now supports compression via the “permessage-deflate” extension. OverrideWebSocketHandler.get_compression_options
to enable on the server side, and use thecompression_options
keyword argument towebsocket_connect
on the client side. WebSocketHandler
no longer logs stack traces when the connection is closed.WebSocketHandler.open
now accepts*args, **kw
for consistency withRequestHandler.get
and related methods.- The
Sec-WebSocket-Version
header now includes all supported versions. websocket_connect
now has aon_message_callback
keyword argument for callback-style use withoutread_message()
.