diff --git a/asyncpg/connection.py b/asyncpg/connection.py index 1644ba0b..858c9daf 100644 --- a/asyncpg/connection.py +++ b/asyncpg/connection.py @@ -46,7 +46,7 @@ class Connection(metaclass=ConnectionMeta): '_listeners', '_server_version', '_server_caps', '_intro_query', '_reset_query', '_proxy', '_stmt_exclusive_section', '_config', '_params', '_addr', - '_log_listeners', '_cleanup_listeners', '_cancellations', + '_log_listeners', '_close_listeners', '_cancellations', '_source_traceback', '__weakref__') def __init__(self, protocol, transport, loop, @@ -78,7 +78,7 @@ def __init__(self, protocol, transport, loop, self._listeners = {} self._log_listeners = set() self._cancellations = set() - self._cleanup_listeners = set() + self._close_listeners = set() settings = self._protocol.get_settings() ver_string = settings.server_version @@ -186,11 +186,11 @@ def add_close_listener(self, callback): A callable receiving one argument: **connection**: a Connection the callback is registered with. """ - self._cleanup_listeners.add(callback) + self._close_listeners.add(callback) def remove_close_listener(self, callback): """Remove a listening callback for the connection closing.""" - self._cleanup_listeners.discard(callback) + self._close_listeners.discard(callback) def get_server_pid(self): """Return the PID of the Postgres server the connection is bound to.""" @@ -1134,7 +1134,7 @@ def _abort(self): self._protocol = None def _cleanup(self): - self._call_cleanup_listeners() + self._call_close_listeners() # Free the resources associated with this connection. # This must be called when a connection is terminated. @@ -1252,12 +1252,12 @@ def _call_log_listener(self, cb, con_ref, message): 'exception': ex }) - def _call_cleanup_listeners(self): - if not self._cleanup_listeners: + def _call_close_listeners(self): + if not self._close_listeners: return con_ref = self._unwrap() - for cb in self._cleanup_listeners: + for cb in self._close_listeners: try: cb(con_ref) except Exception as ex: @@ -1267,7 +1267,7 @@ def _call_cleanup_listeners(self): 'exception': ex }) - self._cleanup_listeners.clear() + self._close_listeners.clear() def _process_notification(self, pid, channel, payload): if channel not in self._listeners: