Blocking-request

Hi, guys:

I built a sanic app like this:

from sanic import Sanic
from sanic.response import text

app = Sanic(__name__)

@app.route("/download-tile", methods=frozenset({"POST"}))
async def download_tile(request):
    res = awati SEND_AYNC_REQUESTS(request.json["url"])  # assume it takes seconds to get the response
    return text(res.body)

I found that when A sent a request to /download-tile, sanic will send a async request for A.

meanwhile, B also sent a request to /download-tile, but A’s request is pending, sanic can’t send requset for B.

how to make sanic send async request for A and B the same time?

Really? That doesn’t sound right. What are you using to send those requests?

I just tried the following example:

server1.py

import httpx
from sanic import Sanic
from sanic.response import text

app = Sanic("__BASE__")


@app.get("/")
async def get1(request):
    print("Hitting server2")
    async with httpx.AsyncClient() as client:
        response = await client.get("http://localhost:9999/")
    return text(response.text)


if __name__ == "__main__":
    app.run(auto_reload=True, port=8888)

server2.py

import asyncio

from sanic import Sanic
from sanic.response import text

app = Sanic("__BASE__")


@app.get("/")
async def get1(request):
    print("request received, going to sleep")
    await asyncio.sleep(3)
    return text("I'm awake!")


if __name__ == "__main__":
    app.run(auto_reload=True, port=9999)

With these running in side by side terminal sessions, I was able to fire off simultaneous requests to server1 and see them propagate as expected, asynchronously.

Thanks!

And I found it’s anohter chrome issue actually!

The second request is Stalled before the first request is responsed.

l’ll use other browser to do my test since now.