File tree Expand file tree Collapse file tree 5 files changed +32
-0
lines changed Expand file tree Collapse file tree 5 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -240,6 +240,7 @@ def cancel(self):
240
240
change the future's state to cancelled, schedule the callbacks and
241
241
return True.
242
242
"""
243
+ self ._log_traceback = False
243
244
if self ._state != _PENDING :
244
245
return False
245
246
self ._state = _CANCELLED
Original file line number Diff line number Diff line change @@ -208,6 +208,7 @@ def cancel(self):
208
208
terminates with a CancelledError exception (even if cancel()
209
209
was not called).
210
210
"""
211
+ self ._log_traceback = False
211
212
if self .done ():
212
213
return False
213
214
if self ._fut_waiter is not None :
Original file line number Diff line number Diff line change @@ -314,6 +314,14 @@ def test_tb_logger_abandoned(self, m_log):
314
314
del fut
315
315
self .assertFalse (m_log .error .called )
316
316
317
+ @mock .patch ('asyncio.base_events.logger' )
318
+ def test_tb_logger_not_called_after_cancel (self , m_log ):
319
+ fut = asyncio .Future (loop = self .loop )
320
+ fut .set_exception (Exception ())
321
+ fut .cancel ()
322
+ del fut
323
+ self .assertFalse (m_log .error .called )
324
+
317
325
@mock .patch ('asyncio.base_events.logger' )
318
326
def test_tb_logger_result_unretrieved (self , m_log ):
319
327
fut = asyncio .Future (loop = self .loop )
Original file line number Diff line number Diff line change @@ -1828,6 +1828,25 @@ def kill_me(loop):
1828
1828
})
1829
1829
mock_handler .reset_mock ()
1830
1830
1831
+ @mock .patch ('asyncio.base_events.logger' )
1832
+ def test_tb_logger_not_called_after_cancel (self , m_log ):
1833
+ loop = asyncio .new_event_loop ()
1834
+ self .set_event_loop (loop )
1835
+
1836
+ @asyncio .coroutine
1837
+ def coro ():
1838
+ raise TypeError
1839
+
1840
+ @asyncio .coroutine
1841
+ def runner ():
1842
+ task = loop .create_task (coro ())
1843
+ yield from asyncio .sleep (0.05 , loop = loop )
1844
+ task .cancel ()
1845
+ task = None
1846
+
1847
+ loop .run_until_complete (runner ())
1848
+ self .assertFalse (m_log .error .called )
1849
+
1831
1850
@mock .patch ('asyncio.coroutines.logger' )
1832
1851
def test_coroutine_never_yielded (self , m_log ):
1833
1852
with set_coroutine_debug (True ):
Original file line number Diff line number Diff line change @@ -56,6 +56,9 @@ Extension Modules
56
56
Library
57
57
-------
58
58
59
+ - bpo-30508: Don't log exceptions if Task/Future "cancel()" method was
60
+ called.
61
+
59
62
- bpo-28556: Updates to typing module: Add generic AsyncContextManager, add
60
63
support for ContextManager on all versions. Original PRs by Jelle Zijlstra
61
64
and Ivan Levkivskyi
You can’t perform that action at this time.
0 commit comments