@@ -986,6 +986,8 @@ async def _connect_sock(self, exceptions, addr_info, local_addr_infos=None):
986986 if sock is not None :
987987 sock .close ()
988988 raise
989+ finally :
990+ exceptions = my_exceptions = None
989991
990992 async def create_connection (
991993 self , protocol_factory , host = None , port = None ,
@@ -1084,19 +1086,22 @@ async def create_connection(
10841086
10851087 if sock is None :
10861088 exceptions = [exc for sub in exceptions for exc in sub ]
1087- if all_errors :
1088- raise ExceptionGroup ("create_connection failed" , exceptions )
1089- if len (exceptions ) == 1 :
1090- raise exceptions [0 ]
1091- else :
1092- # If they all have the same str(), raise one.
1093- model = str (exceptions [0 ])
1094- if all (str (exc ) == model for exc in exceptions ):
1089+ try :
1090+ if all_errors :
1091+ raise ExceptionGroup ("create_connection failed" , exceptions )
1092+ if len (exceptions ) == 1 :
10951093 raise exceptions [0 ]
1096- # Raise a combined exception so the user can see all
1097- # the various error messages.
1098- raise OSError ('Multiple exceptions: {}' .format (
1099- ', ' .join (str (exc ) for exc in exceptions )))
1094+ else :
1095+ # If they all have the same str(), raise one.
1096+ model = str (exceptions [0 ])
1097+ if all (str (exc ) == model for exc in exceptions ):
1098+ raise exceptions [0 ]
1099+ # Raise a combined exception so the user can see all
1100+ # the various error messages.
1101+ raise OSError ('Multiple exceptions: {}' .format (
1102+ ', ' .join (str (exc ) for exc in exceptions )))
1103+ finally :
1104+ exceptions = None
11001105
11011106 else :
11021107 if sock is None :
@@ -1904,6 +1909,8 @@ def _run_once(self):
19041909
19051910 event_list = self ._selector .select (timeout )
19061911 self ._process_events (event_list )
1912+ # Needed to break cycles when an exception occurs.
1913+ event_list = None
19071914
19081915 # Handle 'later' callbacks that are ready.
19091916 end_time = self .time () + self ._clock_resolution
0 commit comments