提交 172557e4 编写于 作者: B Ben Darnell

iostream: Deprecate streaming_callback arguments

Currently, mixing futures and streaming_callback does not guarantee
ordering (so the returned future could become ready before the last
streaming_callback fires). Specifically, this happens with
test_streaming_read_until_close_after_close if that test is modified
to not use the callback argument. This would cause problems when we
remove the callback argument if we left streaming_callback in place.

These problems are solvable, but probably not worth it since
partial=True is an alternative (and used internally instead of
streaming_callback).
上级 58067883
...@@ -423,14 +423,19 @@ class BaseIOStream(object): ...@@ -423,14 +423,19 @@ class BaseIOStream(object):
.. deprecated:: 5.1 .. deprecated:: 5.1
The ``callback`` argument is deprecated and will be removed The ``callback`` and ``streaming_callback`` arguments are
in Tornado 6.0. Use the returned `.Future` instead. deprecated and will be removed in Tornado 6.0. Use the
returned `.Future` (and ``partial=True`` for
``streaming_callback``) instead.
""" """
future = self._set_read_callback(callback) future = self._set_read_callback(callback)
assert isinstance(num_bytes, numbers.Integral) assert isinstance(num_bytes, numbers.Integral)
self._read_bytes = num_bytes self._read_bytes = num_bytes
self._read_partial = partial self._read_partial = partial
if streaming_callback is not None:
warnings.warn("streaming_callback is deprecated, use partial instead",
DeprecationWarning)
self._streaming_callback = stack_context.wrap(streaming_callback) self._streaming_callback = stack_context.wrap(streaming_callback)
try: try:
self._try_inline_read() self._try_inline_read()
...@@ -511,11 +516,16 @@ class BaseIOStream(object): ...@@ -511,11 +516,16 @@ class BaseIOStream(object):
.. deprecated:: 5.1 .. deprecated:: 5.1
The ``callback`` argument is deprecated and will be removed The ``callback`` and ``streaming_callback`` arguments are
in Tornado 6.0. Use the returned `.Future` instead. deprecated and will be removed in Tornado 6.0. Use the
returned `.Future` (and `read_bytes` with ``partial=True``
for ``streaming_callback``) instead.
""" """
future = self._set_read_callback(callback) future = self._set_read_callback(callback)
if streaming_callback is not None:
warnings.warn("streaming_callback is deprecated, use read_bytes(partial=True) instead",
DeprecationWarning)
self._streaming_callback = stack_context.wrap(streaming_callback) self._streaming_callback = stack_context.wrap(streaming_callback)
if self.closed(): if self.closed():
if self._streaming_callback is not None: if self._streaming_callback is not None:
......
...@@ -195,6 +195,7 @@ class TestReadWriteMixin(object): ...@@ -195,6 +195,7 @@ class TestReadWriteMixin(object):
chunks.append(data) chunks.append(data)
cond.notify() cond.notify()
with ignore_deprecation():
fut = rs.read_bytes(6, streaming_callback=streaming_callback) fut = rs.read_bytes(6, streaming_callback=streaming_callback)
ws.write(b"1234") ws.write(b"1234")
while not chunks: while not chunks:
...@@ -253,6 +254,7 @@ class TestReadWriteMixin(object): ...@@ -253,6 +254,7 @@ class TestReadWriteMixin(object):
self.assertEqual(data, b"abcd\r\n") self.assertEqual(data, b"abcd\r\n")
streaming_fut = Future() streaming_fut = Future()
with ignore_deprecation():
rs.read_until_close(streaming_callback=streaming_fut.set_result) rs.read_until_close(streaming_callback=streaming_fut.set_result)
data = yield streaming_fut data = yield streaming_fut
self.assertEqual(data, b"efgh") self.assertEqual(data, b"efgh")
...@@ -298,6 +300,7 @@ class TestReadWriteMixin(object): ...@@ -298,6 +300,7 @@ class TestReadWriteMixin(object):
@gen.coroutine @gen.coroutine
def rs_task(): def rs_task():
with ignore_deprecation():
yield rs.read_until_close(streaming_callback=chunks.append) yield rs.read_until_close(streaming_callback=chunks.append)
@gen.coroutine @gen.coroutine
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册