@@ -971,6 +971,8 @@ async def _connect_sock(self, exceptions, addr_info, local_addr_infos=None):
971971 if sock is not None :
972972 sock .close ()
973973 raise
974+ finally :
975+ exceptions = my_exceptions = None
974976
975977 async def create_connection (
976978 self , protocol_factory , host = None , port = None ,
@@ -1063,17 +1065,20 @@ async def create_connection(
10631065
10641066 if sock is None :
10651067 exceptions = [exc for sub in exceptions for exc in sub ]
1066- if len (exceptions ) == 1 :
1067- raise exceptions [0 ]
1068- else :
1069- # If they all have the same str(), raise one.
1070- model = str (exceptions [0 ])
1071- if all (str (exc ) == model for exc in exceptions ):
1068+ try :
1069+ if len (exceptions ) == 1 :
10721070 raise exceptions [0 ]
1073- # Raise a combined exception so the user can see all
1074- # the various error messages.
1075- raise OSError ('Multiple exceptions: {}' .format (
1076- ', ' .join (str (exc ) for exc in exceptions )))
1071+ else :
1072+ # If they all have the same str(), raise one.
1073+ model = str (exceptions [0 ])
1074+ if all (str (exc ) == model for exc in exceptions ):
1075+ raise exceptions [0 ]
1076+ # Raise a combined exception so the user can see all
1077+ # the various error messages.
1078+ raise OSError ('Multiple exceptions: {}' .format (
1079+ ', ' .join (str (exc ) for exc in exceptions )))
1080+ finally :
1081+ exceptions = None
10771082
10781083 else :
10791084 if sock is None :
@@ -1862,6 +1867,8 @@ def _run_once(self):
18621867
18631868 event_list = self ._selector .select (timeout )
18641869 self ._process_events (event_list )
1870+ # Needed to break cycles when an exception occurs.
1871+ event_list = None
18651872
18661873 # Handle 'later' callbacks that are ready.
18671874 end_time = self .time () + self ._clock_resolution
0 commit comments