Repository: tornadoweb/tornado

Issue:
Fix python 3.8 CI
CI is currently failing on python 3.8 nightly, so this configuration is disabled by https://github.com/tornadoweb/tornado/pull/2673/commits/ecd42b610d88635dbc17cebad70b70289e6b711b
gen.with_timeout: Don't log CancelledError after timeout
Hello!
I'm not very familiar with Tornado, but I'm investigating the failure on Python 3.8 (#2677).
From commit a237a995a1d54ad6e07c1ecdf5103ff8f45073b5, it seems that CancelledError should also be ignored in `tornado.gen.with_timeout`'s `error_callback`. Is that right?

This fixed tests on Python 3.8.0b1 for me.



Discussion:
The errors are:

```
[E 190617 00:22:54 base_events:1692] Exception in callback with_timeout.<locals>.error_callback(<Future cancelled>) at /home/travis/build/tornadoweb/tornado/tornado/gen.py:587
    handle: <Handle with_timeout.<locals>.error_callback(<Future cancelled>) at /home/travis/build/tornadoweb/tornado/tornado/gen.py:587>
    Traceback (most recent call last):
      File "/opt/python/3.8-dev/lib/python3.8/asyncio/events.py", line 81, in _run
        self._context.run(self._callback, *self._args)
      File "/home/travis/build/tornadoweb/tornado/tornado/gen.py", line 589, in error_callback
        future.result()
    asyncio.exceptions.CancelledError

[E 190617 00:22:55 base_events:1692] Exception in callback with_timeout.<locals>.error_callback(<Future cancelled>) at /home/travis/build/tornadoweb/tornado/tornado/gen.py:587
    handle: <Handle with_timeout.<locals>.error_callback(<Future cancelled>) at /home/travis/build/tornadoweb/tornado/tornado/gen.py:587>
    Traceback (most recent call last):
      File "/opt/python/3.8-dev/lib/python3.8/asyncio/events.py", line 81, in _run
        self._context.run(self._callback, *self._args)
      File "/home/travis/build/tornadoweb/tornado/tornado/gen.py", line 589, in error_callback
        future.result()
    asyncio.exceptions.CancelledError

[E 190617 00:22:56 base_events:1692] Exception in callback with_timeout.<locals>.error_callback(<Future cancelled>) at /home/travis/build/tornadoweb/tornado/tornado/gen.py:587
    handle: <Handle with_timeout.<locals>.error_callback(<Future cancelled>) at /home/travis/build/tornadoweb/tornado/tornado/gen.py:587>
    Traceback (most recent call last):
      File "/opt/python/3.8-dev/lib/python3.8/asyncio/events.py", line 81, in _run
        self._context.run(self._callback, *self._args)
      File "/home/travis/build/tornadoweb/tornado/tornado/gen.py", line 589, in error_callback
        future.result()
    asyncio.exceptions.CancelledError

[E 190617 00:22:56 base_events:1692] Exception in callback with_timeout.<locals>.error_callback(<Future cancelled>) at /home/travis/build/tornadoweb/tornado/tornado/gen.py:587
    handle: <Handle with_timeout.<locals>.error_callback(<Future cancelled>) at /home/travis/build/tornadoweb/tornado/tornado/gen.py:587>
    Traceback (most recent call last):
      File "/opt/python/3.8-dev/lib/python3.8/asyncio/events.py", line 81, in _run
        self._context.run(self._callback, *self._args)
      File "/home/travis/build/tornadoweb/tornado/tornado/gen.py", line 589, in error_callback
        future.result()
    asyncio.exceptions.CancelledError
```

We have the same errors in Fedora with tornado 6.0.2.
> We have the same errors in Fedora with tornado 6.0.2.

You mean with Python 3.8.0b1, or are you seeing these errors somehow on other versions of python?


Resolving patch:
diff --git a/tornado/gen.py b/tornado/gen.py
--- a/tornado/gen.py
+++ b/tornado/gen.py
@@ -559,7 +559,7 @@ def with_timeout(
     If the wrapped `.Future` fails after it has timed out, the exception
     will be logged unless it is either of a type contained in
     ``quiet_exceptions`` (which may be an exception type or a sequence of
-    types), or a ``CancelledError``.
+    types), or an ``asyncio.CancelledError``.
 
     The wrapped `.Future` is not canceled when the timeout expires,
     permitting it to be reused. `asyncio.wait_for` is similar to this
@@ -574,8 +574,8 @@ def with_timeout(
     .. versionchanged:: 4.4
        Added support for yieldable objects other than `.Future`.
 
-    .. versionchanged:: 6.1
-       Do not log CancelledError after timeout.
+    .. versionchanged:: 6.0.3
+       ``asyncio.CancelledError`` is now always considered "quiet".
 
     """
     # It's tempting to optimize this by cancelling the input future on timeout
diff --git a/tornado/locks.py b/tornado/locks.py
--- a/tornado/locks.py
+++ b/tornado/locks.py
@@ -13,7 +13,6 @@
 # under the License.
 
 import collections
-from concurrent.futures import CancelledError
 import datetime
 import types
 
@@ -250,9 +249,7 @@ def wait(
         if timeout is None:
             return fut
         else:
-            timeout_fut = gen.with_timeout(
-                timeout, fut, quiet_exceptions=(CancelledError,)
-            )
+            timeout_fut = gen.with_timeout(timeout, fut)
             # This is a slightly clumsy workaround for the fact that
             # gen.with_timeout doesn't cancel its futures. Cancelling
             # fut will remove it from the waiters list.


Test patch: