-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async client support #26
Comments
To resolve this initialisation bug, either:
I like the 2nd option
|
⇣
|
Made an attempt and undone it, leaving only the initial outline - needs to be clarified where would I want to |
This should be made much easier by the introduction of a single stream 'mode' (see #29), as there'll be only one call to await (?) |
I think it may be desirable to leave the async requesting to the [package-external] fetch function, and just allow the creation (or modification) of a PngStream from the successfully obtained async response (in fact, are responses async?) It's important to get the async abstraction at the right level, which is in the loop creating RangeStream objects (not within the creation of a single RangeStream). The point being that creating multiple monostreams in series will be slower than creating multiple monostreams parallelised asynchronously (as the GIL is not blocked between awaiting the response from one sent async request and sending the next) |
A All >>> import httpx
>>> from range_streams import _EXAMPLE_URL
>>> import asyncio
>>> c = httpx.AsyncClient()
>>> req = c.build_request("GET", _EXAMPLE_URL)
>>> req_send_coro = c.send(request=req, stream=True)
>>> resp = asyncio.run(req_send_coro)
>>> stream = resp.aiter_bytes()
>>> async def gimme(stream):
... async for b in stream:
... return b
...
>>> respval = asyncio.run(gimme(stream))
>>> respval
<Response [200 OK]>
>>> bytesval = asyncio.run(gimme(stream))
>>> bytesval
b'P\x00\x01\x02\x03\x04\x05\x06\x07\x08K' where the async function incorrect use (sync iterator with async generator/async iterator with sync generator) throws an error, e.g. >>> sync_c = httpx.Client()
>>> sync_req = sync_c.build_request("GET", _EXAMPLE_URL)
>>> sync_resp = sync_c.send(sync_req, stream=True) # not a coroutine
>>> asyncio.run(sync_resp) # using as if it were a coroutine
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/louis/miniconda3/envs/rangestreams/lib/python3.9/asyncio/runners.py", line 37, in run
raise ValueError("a coroutine was expected, got {!r}".format(main))
ValueError: a coroutine was expected, got <Response [200 OK]>
|
The following methods will need to involve an async check:
Additionally, the |
range-streams/src/range_streams/stream.py Lines 741 to 785 in f4419e7
I didn't like any of the options given here to make the |
Still to do:
|
Implemented: 68604a7
|
I wasn't using the range-streams/src/range_streams/response.py Lines 348 to 358 in 68604a7
in the |
This library doesn't support usage of async clients
⇣
The text was updated successfully, but these errors were encountered: