轻松聆听和通知 PostgreSQL 通知系统
项目描述
pgnotify_u:更新了 pgnotify 模块。一个 python 库,可以通过 PostgreSQL 通知系统轻松监听和通知
例子
for用一个简单的循环来监听和处理 NOTIFY 事件,如下所示:
from pgnotify import await_pg_notifications
for notification in await_pg_notifications(
'postgresql:///example',
['channel1', 'channel2']):
print(notification.channel)
print(notification.payload)
示例 2
通知:
from pgnotify import pg_notify
pg_notify("postgresql:///example", 'channel1', 'hello')
安装
可使用 python 包索引中的任何 python 包管理器安装,例如:
pip install pgnotify_u
所有的花里胡哨
您还可以处理超时和信号,如这个更完整的示例中所示:
import signal
from pgnotify import await_pg_notifications, get_dbapi_connection
# the first parameter of the await_pg_notifications
# loop is a dbapi connection in autocommit mode
CONNECT = "postgresql:///example"
# use this convenient method to create the right connection
# from a database URL
e = get_dbapi_connection(CONNECT)
SIGNALS_TO_HANDLE = [signal.SIGINT, signal.SIGTERM]
for n in await_pg_notifications(
e,
["hello", "hello2"],
timeout=10,
yield_on_timeout=True,
handle_signals=SIGNALS_TO_HANDLE,
):
# the integer code of the signal is yielded on each
# occurrence of a handled signal
if isinstance(n, int):
sig = signal.Signals(n)
print(f"handling {sig.name}, stopping")
break
# the `yield_on_timeout` option makes the
# loop yield `None` on timeout
elif n is None:
print("timeout, continuing")
# handle the actual notify occurrences here
else:
print((n.pid, n.channel, n.payload))
进一步的文件来。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。
源分布
pgnotify_u-0.2.tar.gz
(4.9 kB
查看哈希)
内置分布
pgnotify_u-0.2-py2.py3-none-any.whl
(4.9 kB
查看哈希)
关
pgnotify_u -0.2.tar.gz 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | 9cd07550c5a7492522a06e56044cf4d31845fe2195e80e6795ff29608a29eef4 |
|
| MD5 | 9952af276773d9fa9e42fd451e4a9dd8 |
|
| 布莱克2-256 | 0351d7c51b3b078b27bfa6b2e6d50ea84e9fcf67f00fca05b22d2df8ce2a65f7 |
关
pgnotify_u -0.2-py2.py3-none-any.whl 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | 640665a46df4dad66bd642590905b545afb9991e636d240d8fc42453a03bef2e |
|
| MD5 | 9a20e79afc7294c3adc6de61ee155d50 |
|
| 布莱克2-256 | d829c2d78d37b8c1f86cbb3ec170a5ff81174ac867f6761e912d02b01961fc10 |