Impossible to use w/o the context manager? #27
-
I need to use it w/o one, and it appears I can't do that. Any solutions? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Yes, it only works as context manager. Under the hood, it uses If you really can't use a context manager, a nice trick is to use an exit_stack = contextlib.ExitStack()
ws = exit_stack.enter_context(connect_ws("http://localhost:8000/ws"))
message = ws.receive_text()
exit_stack.close() |
Beta Was this translation helpful? Give feedback.
-
Thank you! I've found just now #11, and have already utilized the hints given there right when you replied. The key limitation was that the entry point is forced to stay synchronous, but I could spin off an asynchronous function in order to create the |
Beta Was this translation helpful? Give feedback.
Yes, it only works as context manager. Under the hood, it uses
httpx.stream
, which is a context manager itself.If you really can't use a context manager, a nice trick is to use an
ExitStack
(orAsyncExitStack
for async) from the standardcontextlib
.