Tornado 4.1 新特性¶

Feb 7, 2015¶

Highlights¶

  • If a Future contains an exception but that exception is neverexamined or re-raised (e.g. by yielding the Future), a stacktrace will be logged when the Future is garbage-collected.
  • New class tornado.gen.WaitIterator provides a way to iterateover Futures 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 serverside, and use the compression_options keyword argument towebsocket_connect on the client side.
  • When the appropriate packages are installed, it is possible to yieldasyncio.Future or Twisted Defered objects in Tornado coroutines.

Backwards-compatibility notes¶

  • HTTPServer now calls start_request with the correctarguments. This change is backwards-incompatible, afffecting anyapplication which implemented HTTPServerConnectionDelegate byfollowing the example of Application instead of the documentedmethod signatures.

tornado.concurrent¶

  • If a Future contains an exception but that exception is neverexamined or re-raised (e.g. by yielding the Future), a stacktrace will be logged when the Future is garbage-collected.
  • Future now catches and logs exceptions in its callbacks.

tornado.curl_httpclient¶

  • tornado.curl_httpclient now supports request bodies for PATCHand custom methods.
  • tornado.curl_httpclient now supports resubmitting bodies afterfollowing redirects for methods other than POST.
  • curl_httpclient now runs the streaming and header callbacks onthe IOLoop.
  • tornado.curl_httpclient now uses its own logger for debug outputso it can be filtered more easily.

tornado.gen¶

  • New class tornado.gen.WaitIterator provides a way to iterateover Futures in the order they resolve.
  • When the singledispatch library is available (standard onPython 3.4, available via pip install singledispatch on older versions),the convert_yielded function can be used to make other kinds of objectsyieldable in coroutines.
  • New function tornado.gen.sleep is a coroutine-friendlyanalogue to time.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 anerror for non-200 response codes.

tornado.httpserver¶

  • HTTPServer now calls start_request with the correctarguments. This change is backwards-incompatible, afffecting anyapplication which implemented HTTPServerConnectionDelegate byfollowing the example of Application instead of the documentedmethod signatures.
  • HTTPServer now tolerates extra newlines which are sometimes insertedbetween requests on keep-alive connections.
  • HTTPServer can now use keep-alive connections after a requestwith a chunked body.
  • HTTPServer now always reports HTTP/1.1 instead of echoingthe request version.

tornado.httputil¶

  • New function tornado.httputil.split_host_and_port for parsingthe netloc portion of URLs.
  • The context argument to HTTPServerRequest is now optional,and if a context is supplied the remote_ip attribute is also optional.
  • HTTPServerRequest.body is now always a byte string (previously the defaultempty body would be a unicode string on python 3).
  • Header parsing now works correctly when newline-like unicode charactersare present.
  • Header parsing again supports both CRLF and bare LF line separators.
  • Malformed multipart/form-data bodies will always be loggedquietly instead of raising an unhandled exception; previouslythe behavior was inconsistent depending on the exact error.

tornado.ioloop¶

  • The kqueue and select IOLoop implementations now reportwriteability 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 seewhether the PeriodicCallback has been started.

tornado.iostream¶

  • IOStream.start_tls now uses the server_hostname parameterfor certificate validation.
  • SSLIOStream will no longer consume 100% CPU after certain error conditions.
  • SSLIOStream no longer logs EBADF errors during the handshake as theycan result from nmap scans in certain modes.

tornado.options¶

tornado.platform.asyncio¶

  • It is now possible to yield asyncio.Future objects in coroutineswhen the singledispatch library is available andtornado.platform.asyncio has been imported.
  • New methods tornado.platform.asyncio.to_tornado_future andto_asyncio_future convert betweenthe two libraries’ Future classes.

tornado.platform.twisted¶

  • It is now possible to yield Deferred objects in coroutineswhen the singledispatch library is available andtornado.platform.twisted has been imported.

tornado.tcpclient¶

  • TCPClient will no longer raise an exception due to an ill-timedtimeout.

tornado.tcpserver¶

  • TCPServer no longer ignores its read_chunk_size argument.

tornado.testing¶

  • AsyncTestCase has better support for multiple exceptions. Previouslyit would silently swallow all but the last; now it raises the firstand logs all the rest.
  • AsyncTestCase now cleans up Subprocess state on tearDown whennecessary.

tornado.web¶

tornado.websocket¶

原文:

https://tornado-zh-cn.readthedocs.io/zh_CN/latest/releases/v4.1.0.html