Skip to content

Commit

Permalink
close_listeners: rename from "cleanup listeners" internally to "close…
Browse files Browse the repository at this point in the history
… listeners"
  • Loading branch information
ioistired committed Jan 15, 2020
1 parent 171bb2f commit 331bb89
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions asyncpg/connection.py
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 331bb89

Please sign in to comment.