File tree Expand file tree Collapse file tree 3 files changed +20
-0
lines changed Expand file tree Collapse file tree 3 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -370,6 +370,8 @@ async def foo():
370
370
self .assertIn ('test_debug_slow_task_callbacks' , msg )
371
371
372
372
def test_default_exc_handler_callback (self ):
373
+ self .loop .set_exception_handler (None )
374
+
373
375
self .loop ._process_events = mock .Mock ()
374
376
375
377
def zero_error (fut ):
@@ -399,6 +401,7 @@ def zero_error(fut):
399
401
exc_info = mock .ANY )
400
402
401
403
def test_set_exc_handler_custom (self ):
404
+ self .loop .set_exception_handler (None )
402
405
logger = logging .getLogger ('asyncio' )
403
406
404
407
def run_loop ():
Original file line number Diff line number Diff line change @@ -1048,6 +1048,10 @@ async def start_server():
1048
1048
client .stop ()
1049
1049
1050
1050
def test_create_connection_ssl_1 (self ):
1051
+ if self .implementation == 'asyncio' :
1052
+ # Don't crash on asyncio errors
1053
+ self .loop .set_exception_handler (None )
1054
+
1051
1055
CNT = 0
1052
1056
TOTAL_CNT = 25
1053
1057
Original file line number Diff line number Diff line change 8
8
import gc
9
9
import logging
10
10
import os
11
+ import pprint
11
12
import re
12
13
import select
13
14
import socket
@@ -71,11 +72,17 @@ def is_asyncio_loop(self):
71
72
def run_loop_briefly (self , * , delay = 0.01 ):
72
73
self .loop .run_until_complete (asyncio .sleep (delay , loop = self .loop ))
73
74
75
+ def loop_exception_handler (self , loop , context ):
76
+ self .__unhandled_exceptions .append (context )
77
+
74
78
def setUp (self ):
75
79
self .loop = self .new_loop ()
76
80
asyncio .set_event_loop (None )
77
81
self ._check_unclosed_resources_in_debug = True
78
82
83
+ self .loop .set_exception_handler (self .loop_exception_handler )
84
+ self .__unhandled_exceptions = []
85
+
79
86
if hasattr (asyncio , '_get_running_loop' ):
80
87
# Disable `_get_running_loop`.
81
88
self ._get_running_loop = asyncio .events ._get_running_loop
@@ -84,6 +91,12 @@ def setUp(self):
84
91
def tearDown (self ):
85
92
self .loop .close ()
86
93
94
+ if self .__unhandled_exceptions :
95
+ print ('Unexpected calls to loop.call_exception_handler():' )
96
+ pprint .pprint (self .__unhandled_exceptions )
97
+ self .fail ('unexpected calls to loop.call_exception_handler()' )
98
+ return
99
+
87
100
if hasattr (asyncio , '_get_running_loop' ):
88
101
asyncio .events ._get_running_loop = self ._get_running_loop
89
102
You can’t perform that action at this time.
0 commit comments