How to fix userwarning
yxlwfds opened this issue · comments
UserWarning: Unclosed <httpx.AsyncClient object at 0x10ed159d0>. See https://www.python-httpx.org/async/#opening-and-closing-clients for details.
versions:
Successfully installed httpcore-0.12.3 httpx-0.16.1 msgpack-1.0.2 pydantic-1.7.3 rfc3986-1.4.0 rpc.py-0.4.3 sniffio-1.2.0
use https://github1s.com/abersheeran/rpc.py/blob/master/examples/async_client.py and async_server.py
my script:
from rpcclient import sayhi
import asyncio
async def run():
result = await sayhi("quantex")
print(result)
return result
if __name__ == '__main__':
asyncio.run(run())
Call httpx.AsyncClient
instance .aclose()
before your code exit.
https://www.python-httpx.org/async/#opening-and-closing-clients
Tks, Is it autoclose if i use sync model?
Maybe not. It depends on the mechanism of httpx.
Because it is a dependency injection design, rpcpy.Client
does not try to manage third-party objects. Users need to properly manage the third-party objects used by themselves.