if sock is not None:
sock.close()
raise
+ finally:
+ exceptions = my_exceptions = None
async def create_connection(
self, protocol_factory, host=None, port=None,
if sock is None:
exceptions = [exc for sub in exceptions for exc in sub]
- if all_errors:
- raise ExceptionGroup("create_connection failed", exceptions)
- if len(exceptions) == 1:
- raise exceptions[0]
- else:
- # If they all have the same str(), raise one.
- model = str(exceptions[0])
- if all(str(exc) == model for exc in exceptions):
+ try:
+ if all_errors:
+ raise ExceptionGroup("create_connection failed", exceptions)
+ if len(exceptions) == 1:
raise exceptions[0]
- # Raise a combined exception so the user can see all
- # the various error messages.
- raise OSError('Multiple exceptions: {}'.format(
- ', '.join(str(exc) for exc in exceptions)))
+ else:
+ # If they all have the same str(), raise one.
+ model = str(exceptions[0])
+ if all(str(exc) == model for exc in exceptions):
+ raise exceptions[0]
+ # Raise a combined exception so the user can see all
+ # the various error messages.
+ raise OSError('Multiple exceptions: {}'.format(
+ ', '.join(str(exc) for exc in exceptions)))
+ finally:
+ exceptions = None
else:
if sock is None:
event_list = self._selector.select(timeout)
self._process_events(event_list)
+ # Needed to break cycles when an exception occurs.
+ event_list = None
# Handle 'later' callbacks that are ready.
end_time = self.time() + self._clock_resolution
fut = self.create_future()
self._sock_connect(fut, sock, address)
- return await fut
+ try:
+ return await fut
+ finally:
+ # Needed to break cycles when an exception occurs.
+ fut = None
def _sock_connect(self, fut, sock, address):
fd = sock.fileno()
fut.set_exception(exc)
else:
fut.set_result(None)
+ finally:
+ fut = None
def _sock_write_done(self, fd, fut, handle=None):
if handle is None or not handle.cancelled():
fut.set_exception(exc)
else:
fut.set_result(None)
+ finally:
+ fut = None
async def sock_accept(self, sock):
"""Accept a connection.