Combining requests-futures with uvicorn
See original GitHub issueI’m trying to use requests-futures with uvicorn. Currently, this fails with a ConnectionError
stemming from urllib3. I can run the below code just fine normally but when I await
the same coroutine from an API Star request handler there is the mentioned error and I see the following warning:
[asyncio] [WARNING] Executing <Task finished coro=<RequestResponseCycle.run_asgi() done, defined at /usr/local/lib/python3.6/site-packages/uvicorn/protocols/http/httptools_impl.py:381> result=None created at /usr/local/lib/python3.6/site-packages/uvicorn/protocols/http/httptools_impl.py:272> took 5.026 seconds
Maybe that means the requests are not properly run using a ThreadPoolExecutor
?
import asyncio
import uvloop
from requests_futures.sessions import FuturesSession
async def make_requests():
session = FuturesSession(max_workers=1)
# first request is started in background
future_one = session.get('http://httpbin.org/get')
# second requests is started immediately
future_two = session.get('http://httpbin.org/get?foo=bar')
# wait for the first request to complete, if it hasn't already
response_one = future_one.result()
print('response one status: {0}'.format(response_one.status_code))
print(response_one.content)
# wait for the second request to complete, if it hasn't already
response_two = future_two.result()
print('response two status: {0}'.format(response_two.status_code))
print(response_two.content)
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(make_requests())
finally:
loop.close()
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
How does fastapi/uvicorn parallelize requests? - Stack Overflow
I ran an experiment with fastapi and uvicorn that I don't understand the outcome of. On the code @app.get('/loadtest') def root(): ...
Read more >requests-futures - PyPI
Asynchronous Python HTTP Requests for Humans. https://travis-ci.org/ross/requests-futures. Small add-on for the python requests http library.
Read more >dev-lang/python - Gentoo Packages
An interpreted, interactive, object-oriented programming language. https://www.python.org/ · Overview Dependencies QA report Pull requests 2 Bugs 14 ...
Read more >Software-Pakete in »impish«, Unterbereich python - Ubuntu
... python3-deepmerge (0.0.5-3) [universe]: handle merging of nested data structures in ... X; python3-requests-futures (1.0.0-2) [universe]: library for ...
Read more >Пакеты программ в "sid", Подсекция python
... 1.13.1-2 [x32], 1.12-2 [sh4]): Dithered image combination for Python ... python3-uvicorn (0.17.6-1): ASGI server implementation, using uvloop and ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
And it all turned out to be a DNS problem with docker-compose 😡
You can solve it by directly defining the DNS IP in your
docker-compose.yml
. Something like: