You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
AsyncClient makes a blocking call in its constructor, likely occurring in the Document.load method. This can cause the entire application to freeze until the client finishes this initial request.
Example script
This script includes both a function that blocks the event loop (make_request_blocking) and a workaround for that (make_request_non_blocking).
importasynciofromzeep.clientimportAsyncClientasyncdefget_client_non_blocking():
returnawaitasyncio.get_event_loop().run_in_executor(
None, AsyncClient, "http://172.16.1.45"
)
asyncdefget_client_blocking():
""" I usually use the following pattern to create a client: async with AsyncClient("http://172.16.1.45") as client: return await client.service.serviceName(args="args") """returnAsyncClient("http://172.16.1.45")
asyncdefcounter():
foriinrange(10):
print(i, flush=True)
awaitasyncio.sleep(1)
asyncdefmain():
# This one will block the event loop, and you should see# only the first number printed# await asyncio.gather(counter(), get_client_blocking())# This one works as expectedawaitasyncio.gather(counter(), get_client_non_blocking())
if__name__=="__main__":
asyncio.run(main())
Possible solution
Expose a def load() -> None function on Client and an async def load() -> None function on AsyncClient. Those functions could be called inside the __enter__ and __exit__ magic methods if they haven't been called yet.
The text was updated successfully, but these errors were encountered:
Problem
AsyncClient
makes a blocking call in its constructor, likely occurring in theDocument.load
method. This can cause the entire application to freeze until the client finishes this initial request.Example script
This script includes both a function that blocks the event loop (
make_request_blocking
) and a workaround for that (make_request_non_blocking
).Possible solution
Expose a
def load() -> None
function onClient
and anasync def load() -> None
function onAsyncClient
. Those functions could be called inside the__enter__
and__exit__
magic methods if they haven't been called yet.The text was updated successfully, but these errors were encountered: