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
W.is whois信息查询
最短域名W.is 域名whois查询工具,支持99%域名后缀whois查询
Promoted by vsean
fighterhit
V2EX  ›  Python

Python grpc aio client 连接管理

  •  1
     
  •   fighterhit · 2024-05-27 01:34:56 +08:00 · 1179 次点击
    这是一个创建于 425 天前的主题,其中的信息可能已经有所发展或是发生改变。
    python grpc aio client 有没有什么库或方法支持注册回调函数,当和服务端连接断开(比如网络 down 了)时触发注册的回调函数?
    2 条回复    2024-05-30 16:07:50 +08:00
    so1n
        1
    so1n  
       2024-05-29 15:35:49 +08:00
    他不是有个 timeout 参数吗
    fighterhit
        2
    fighterhit  
    OP
       2024-05-30 16:07:50 +08:00
    @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   ·   实用小工具   ·   933 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 19:51 · PVG 03:51 · LAX 12:51 · JFK 15:51
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.