# aiopg-listen
This library simplifies usage of listen/notify with [aiopg](https://github.com/aio-libs/aiopg):
1. Handles lost of a connection
1. Simplifies processing notifications from multiple channels
1. Setups a timeout for receiving a notification
1. Allows to receive all notifications/only last notification depends on `ListenPolicy`.
```python
import asyncio
import aiopg
import aiopg_listen
async def handle_notifications(notification: aiopg_listen.NotificationOrTimeout) -> None:
print(f"{notification} has been received")
listener = aiopg_listen.NotificationListener(aiopg_listen.connect_func())
listener_task = asyncio.create_task(
listener.run(
{"channel": handle_notifications},
policy=aiopg_listen.ListenPolicy.LAST,
notification_timeout=1
)
)
async with aiopg.connect() as connection, connection.cursor() as cursor:
for i in range(42):
await cursor.execute(f"NOTIFY simple, '{i}'")
```
Python库 | aiopg-listen-0.0.3.tar.gz
版权申诉
169 浏览量
2022-04-06
04:03:52
上传
评论
收藏 5KB GZ 举报
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
最新资源
- 基于Javascript和Python的微商城项目设计源码 - MicroMall
- 基于Java的网上订餐系统设计源码 - online ordering system
- 基于Javascript的超级美眉网络资源管理应用模块设计源码
- 基于Typescript和PHP的编程知识储备库设计源码 - study-php
- Screenshot_2024-05-28-11-40-58-177_com.tencent.mm.jpg
- 基于Dart的Flutter小提琴调音器APP设计源码 - violinhelper
- 基于JavaScript和CSS的随寻订购网页设计源码 - web-order
- 基于MATLAB的声纹识别系统设计源码 - VoiceprintRecognition
- 基于Java的微服务插件集合设计源码 - wsy-plugins
- 基于Vue和微信小程序的监理日志系统设计源码 - supervisionLog
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0