Skip to content

Commit e30ae78

Browse files
committed
gen: Adapt to py38 CancelledError changes
python/cpython#13528 broke us in two ways: asyncio.CancelledError is no longer an alias for concurrent.futures.CancelledError and it's now a BaseException. Fixes tornadoweb#2677 Closes tornadoweb#2681
1 parent c50aed0 commit e30ae78

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎tornado/gen.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,17 @@ def with_timeout(
587587
def error_callback(future: Future) -> None:
588588
try:
589589
future.result()
590+
except BaseException as e:
591+
# TODO(bdarnell): How should we handle BaseExceptions here?
592+
# asyncio.CancelledError changed from an Exception to a BaseException
593+
# in Python 3.8, but we (sometimes) included it as a quiet_exception.
594+
# We preserve the pre-3.8 behavior by raising all BaseExceptions
595+
# unless explicitly quieted, but I'm not sure this is the right behavior.
596+
# BaseExceptions should not usually be caught, but i'm not sure there is a
597+
# better way to prevent log spam in this case. Should asyncio.CancelledError
598+
# always be "quiet"?
599+
if not isinstance(e, quiet_exceptions):
600+
raise
590601
except Exception as e:
591602
if not isinstance(e, quiet_exceptions):
592603
app_log.error(

‎tornado/locks.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# under the License.
1414

1515
import collections
16-
from concurrent.futures import CancelledError
16+
from asyncio import CancelledError
1717
import datetime
1818
import types
1919

0 commit comments

Comments
 (0)