]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
iostream: Deprecate streaming_callback arguments
authorBen Darnell <ben@bendarnell.com>
Sun, 22 Apr 2018 01:58:32 +0000 (21:58 -0400)
committerBen Darnell <ben@bendarnell.com>
Mon, 23 Apr 2018 01:21:00 +0000 (21:21 -0400)
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).

tornado/iostream.py
tornado/test/iostream_test.py

index f7f7e3c83ad8b445e10f2ed9dcb29544219310c9..0220e1796b033a3aff0b2842ab843ded3f49231f 100644 (file)
@@ -423,15 +423,20 @@ class BaseIOStream(object):
 
         .. deprecated:: 5.1
 
-           The ``callback`` argument is deprecated and will be removed
-           in Tornado 6.0. Use the returned `.Future` instead.
+           The ``callback`` and ``streaming_callback`` arguments are
+           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)
         assert isinstance(num_bytes, numbers.Integral)
         self._read_bytes = num_bytes
         self._read_partial = partial
-        self._streaming_callback = stack_context.wrap(streaming_callback)
+        if streaming_callback is not None:
+            warnings.warn("streaming_callback is deprecated, use partial instead",
+                          DeprecationWarning)
+            self._streaming_callback = stack_context.wrap(streaming_callback)
         try:
             self._try_inline_read()
         except:
@@ -511,12 +516,17 @@ class BaseIOStream(object):
 
         .. deprecated:: 5.1
 
-           The ``callback`` argument is deprecated and will be removed
-           in Tornado 6.0. Use the returned `.Future` instead.
+           The ``callback`` and ``streaming_callback`` arguments are
+           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)
-        self._streaming_callback = stack_context.wrap(streaming_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)
         if self.closed():
             if self._streaming_callback is not None:
                 self._run_read_callback(self._read_buffer_size, True)
index 200a3a0c3c0843d14741b45d1ae8ee53897021a2..c6049dd463af41c1adbddc8fc13d8ebe7f7409fa 100644 (file)
@@ -195,7 +195,8 @@ class TestReadWriteMixin(object):
                 chunks.append(data)
                 cond.notify()
 
-            fut = rs.read_bytes(6, streaming_callback=streaming_callback)
+            with ignore_deprecation():
+                fut = rs.read_bytes(6, streaming_callback=streaming_callback)
             ws.write(b"1234")
             while not chunks:
                 yield cond.wait()
@@ -253,7 +254,8 @@ class TestReadWriteMixin(object):
         self.assertEqual(data, b"abcd\r\n")
 
         streaming_fut = Future()
-        rs.read_until_close(streaming_callback=streaming_fut.set_result)
+        with ignore_deprecation():
+            rs.read_until_close(streaming_callback=streaming_fut.set_result)
         data = yield streaming_fut
         self.assertEqual(data, b"efgh")
         rs.close()
@@ -298,7 +300,8 @@ class TestReadWriteMixin(object):
 
             @gen.coroutine
             def rs_task():
-                yield rs.read_until_close(streaming_callback=chunks.append)
+                with ignore_deprecation():
+                    yield rs.read_until_close(streaming_callback=chunks.append)
 
             @gen.coroutine
             def ws_task():