Zappa icon indicating copy to clipboard operation
Zappa copied to clipboard

Django async support

Open undiplomatic opened this issue 3 years ago • 1 comments

Context

Django has introduced native async support. It doesn't appear to be supported by Zappa at this time. Is this something that should be supported moving forwards?

Expected Behavior

views.py

# Helper function
async def lets_sleep():
    print('Starting lets_sleep()')
    await asyncio.sleep(5)
    client = httpx.Client()
    response_p = client.get("https://httpbin.org")
    print(response_p)
    print('Ending lets_sleep()')
    return response_p

# ASync view
async def async1(request):
    print('Starting async0 view')
    loop = asyncio.get_event_loop()
    loop.create_task(lets_sleep())
    print('Ending async0 view')
    return HttpResponse("async1")

Expect output:

Starting async0 view
Ending async0 view
Starting lets_sleep()
<Response [200 OK]>
Ending lets_sleep()

Actual Behavior

Starting async0 view
Ending async0 view
Starting lets_sleep()

Possible Fix

Steps to Reproduce

  1. Add helper function
  2. Add async view
  3. Configure urls.py
  4. Call async view from browser

Your Environment

  • Zappa version used: 0.54.1
  • Operating System and Python version: 3.8
  • The output of pip freeze:
  • Link to your project (optional):
  • Your zappa_settings.json:

undiplomatic avatar May 06 '22 06:05 undiplomatic

Lambda is an ephemeral service that spins up an instance to handle each request. Async assumes that you have a long lived process that continuously handles multiple incoming requests, and implemented in order to share process power more effectively.

So async support doesn't seem to make a lot of sense when using lambda. (However, now that docker images are supported it would make sense there)

It needs investigation, but I wouldn't expect any improvement through the use of async and lambda. In fact, with the additional overhead, I would expect performance to degrade when compared to a non-async version.

(I am personally interested in FastAPI, but haven't used it since it seems to require async. BTW - I think django-ninja is similar, but not as light as FastAPI)

monkut avatar Oct 30 '22 00:10 monkut

Hi there! Unfortunately, this Issue has not seen any activity for at least 90 days. If the Issue is still relevant to the latest version of Zappa, please comment within the next 10 days if you wish to keep it open. Otherwise, it will be automatically closed.

github-actions[bot] avatar Apr 03 '24 18:04 github-actions[bot]

Hi there! Unfortunately, this Issue was automatically closed as it had not seen any activity in at least 100 days. If the Issue is still relevant to the latest version of Zappa, please open a new Issue.

github-actions[bot] avatar Apr 13 '24 20:04 github-actions[bot]