``psycopg`` release notes
=========================
+Future releases
+---------------
+
+Psycopg 3.2.4 (unreleased)
+^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+- Make sure that the notifies callback is called during the use of the
+ `~Connection.notifies()` generator (:ticket:`#972`).
+
+
Current release
---------------
n = pgconn.notifies()
if n:
ns.append(n)
+ if pgconn.notify_handler:
+ pgconn.notify_handler(n)
else:
break
gather(worker)
assert dt > 0.5
+
+
+@pytest.mark.slow
+def test_generator_and_handler(conn, conn_cls, dsn):
+ conn.set_autocommit(True)
+ conn.execute("listen foo")
+
+ n1 = None
+ n2 = None
+
+ def set_n2(n):
+ nonlocal n2
+ n2 = n
+
+ conn.add_notify_handler(set_n2)
+
+ def listener():
+ nonlocal n1
+ for n1 in conn.notifies(timeout=1, stop_after=1):
+ pass
+
+ worker = spawn(listener)
+ try:
+ # Make sure the listener is listening
+ if not conn.lock.locked():
+ sleep(0.01)
+
+ with conn_cls.connect(dsn, autocommit=True) as nconn:
+ nconn.execute("notify foo, '1'")
+ finally:
+ gather(worker)
+
+ assert n1
+ assert n2
await gather(worker)
assert dt > 0.5
+
+
+@pytest.mark.slow
+async def test_generator_and_handler(aconn, aconn_cls, dsn):
+ await aconn.set_autocommit(True)
+ await aconn.execute("listen foo")
+
+ n1 = None
+ n2 = None
+
+ def set_n2(n):
+ nonlocal n2
+ n2 = n
+
+ aconn.add_notify_handler(set_n2)
+
+ async def listener():
+ nonlocal n1
+ async for n1 in aconn.notifies(timeout=1, stop_after=1):
+ pass
+
+ worker = spawn(listener)
+ try:
+ # Make sure the listener is listening
+ if not aconn.lock.locked():
+ await asleep(0.01)
+
+ async with await aconn_cls.connect(dsn, autocommit=True) as nconn:
+ await nconn.execute("notify foo, '1'")
+
+ finally:
+ await gather(worker)
+
+ assert n1
+ assert n2