V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
fighterhit
V2EX  ›  Python

Python grpc aio client 连接管理

  •  1
     
  •   fighterhit · 21 天前 · 635 次点击
    python grpc aio client 有没有什么库或方法支持注册回调函数,当和服务端连接断开(比如网络 down 了)时触发注册的回调函数?
    2 条回复    2024-05-30 16:07:50 +08:00
    so1n
        1
    so1n  
       19 天前
    他不是有个 timeout 参数吗
    fighterhit
        2
    fighterhit  
    OP
       18 天前
    @so1n 不是,是想实现类似 python protocol 一样,连接创建和断开自动触发
    ```
    class RpcClient(asyncio.Protocol):
    def __init__(self, service_id):
    self.transport = None
    self.peername = None

    def connection_made(self, transport):
    utils_rpc_client_mgr_inst.add_rpc_client(self)
    logging.info(f'rpc_client_connection_made to {self.peername}')

    def connection_lost(self, exc):
    from utils import rpc_client_mgr_inst as utils_rpc_client_mgr_inst
    logging.error(f'rpc_client_connection_lost to {self.peername}')
    utils_rpc_client_mgr_inst.del_rpc_client(self)
    ```
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2872 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 14:05 · PVG 22:05 · LAX 07:05 · JFK 10:05
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.