V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · May 27, 2024 · 2128 views
    This topic created in 700 days ago, the information mentioned may be changed or developed.
    python grpc aio client 有没有什么库或方法支持注册回调函数,当和服务端连接断开(比如网络 down 了)时触发注册的回调函数?
    2 replies    2024-05-30 16:07:50 +08:00
    so1n
        1
    so1n  
       May 29, 2024
    他不是有个 timeout 参数吗
    fighterhit
        2
    fighterhit  
    OP
       May 30, 2024
    @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)
    ```
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   911 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 22:12 · PVG 06:12 · LAX 15:12 · JFK 18:12
    ♥ Do have faith in what you're doing.