Skip to content

Commit 83d08bd

Browse files
committed
Call listeners using loop.call_soon
1 parent b06114d commit 83d08bd

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

asyncpg/connection.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -923,14 +923,18 @@ def _notify(self, pid, channel, payload):
923923
con_ref = self._proxy
924924

925925
for cb in self._listeners[channel]:
926-
try:
927-
cb(con_ref, pid, channel, payload)
928-
except Exception as ex:
929-
self._loop.call_exception_handler({
930-
'message': 'Unhandled exception in asyncpg notification '
931-
'listener callback {!r}'.format(cb),
932-
'exception': ex
933-
})
926+
self._loop.call_soon(
927+
self._call_notify_cb, cb, con_ref, pid, channel, payload)
928+
929+
def _call_notify_cb(self, cb, con_ref, pid, channel, payload):
930+
try:
931+
cb(con_ref, pid, channel, payload)
932+
except Exception as ex:
933+
self._loop.call_exception_handler({
934+
'message': 'Unhandled exception in asyncpg notification '
935+
'listener callback {!r}'.format(cb),
936+
'exception': ex
937+
})
934938

935939
def _get_reset_query(self):
936940
if self._reset_query is not None:

0 commit comments

Comments
 (0)