question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Combining requests-futures with uvicorn

See original GitHub issue

I’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:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Midnightercommented, Sep 24, 2018

And it all turned out to be a DNS problem with docker-compose 😡

0reactions
Midnightercommented, Sep 28, 2018

You can solve it by directly defining the DNS IP in your docker-compose.yml. Something like:

services:
  web:
    dns:
    - 8.8.8.8
    - 8.8.4.4
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found