【发布时间】:2021-12-23 03:33:43
【问题描述】:
psycopg2 提供some example code for using postgresql notify facilities
import select
import psycopg2
import psycopg2.extensions
conn = psycopg2.connect(DSN)
conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
curs = conn.cursor()
curs.execute("LISTEN test;")
print "Waiting for notifications on channel 'test'"
while True:
if select.select([conn],[],[],5) == ([],[],[]):
print "Timeout"
else:
conn.poll()
while conn.notifies:
notify = conn.notifies.pop(0)
print "Got NOTIFY:", notify.pid, notify.channel, notify.payload
select.select([conn],[],[],5) == ([],[],[]) 代码在做什么?
select.select 的文档表明我们正在努力确保conn 下的套接字“准备好读取”。
psycogp2 连接“准备好读取”是什么意思?
【问题讨论】:
标签: python postgresql psycopg2