Questions tagged [asgi]

ASGI stand for Asynchronous Server Gateway Interface (ASGI), a "spiritual successor to WSGI, intended to provide a standard interface between async-capable Python web servers, frameworks, and applications."

An ASGI app is a a double, asynchronous callable (scope and coroutine). The callable has send and receive awaitables, thus the ability to wait for incoming events and send outgoing events. Events essentially are dictionaries with a predefined format that form the basis of the standard.

Official ASGI documentation

212 questions
7
votes
1 answer

How to properly set pool_size (and max_overflow) in SQLAlchemy for ASGI app

We're building an ASGI app using fastapi, uvicorn, sqlalchemy and PostgreSQL. The question is: how should we set pool_size in create_async_engine to not make it a bottleneck comparing to a WSGI app with multiple workers? As far as I understand, in a…
Viacheslav Zhukov
  • 1,130
  • 9
  • 15
7
votes
2 answers

How to run FastAPI on apache2?

I've developed an api using fastapi that will act as a wrapper that receives sms requests and call the sms api to send said sms and now I'm ready to deploy it. This is the code: import logging import uvicorn from fastapi import FastAPI,…
NegassaB
  • 379
  • 7
  • 24
7
votes
2 answers

`NameError: name 'TypeError' is not defined` in Apache (mod_wsgi)

Install Version Apache apr-1.6.5 apr-util-1.6.1 httpd-2.4.7 mod_wsgi-4.6.8 pcre-8.32 Python 3.8.5 Django 3.1.2 Apache http.conf Listen 3600 WSGISocketPrefix /var/run/wsgi WSGIDaemonProcess project_name…
이경언
  • 156
  • 1
  • 11
7
votes
2 answers

Django 3.0 + Channels + ASGI + TokenAuthMiddleware

I upgraded to Django 3.0 and now I get this error when using websockets + TokenAuthMiddleware: SynchronousOnlyOperation You cannot call this from an async context - use a thread or sync_to_async.
Max Malysh
  • 29,384
  • 19
  • 111
  • 115
7
votes
0 answers

What is the different in Django 3 ASGI and Django 2 + Channels?

django-channels is on my 1st list of material I am going to learn during this new year. But Django 3 also has ASGI feature without any document on it. Then I doubt that what is the different between django-channels use cases VS Django 3 ASGI?
joe
  • 8,383
  • 13
  • 61
  • 109
7
votes
3 answers

Python asyncio skip processing untill function return

I'm still very confused about how asyncio works, so I was trying to set a simple example but couldn't achieve it. The following example is a web server (Quart) that receives a request to generate a large PDF, the server then returns a response…
Mojimi
  • 2,561
  • 9
  • 52
  • 116
6
votes
1 answer

FastAPI responding slowly when calling through other Python app, but fast in cURL

I have an issue that I can't wrap my head around. I have an API service built using FastAPI, and when I try to call any endpoint from another Python script on my local machine, the response takes 2+ seconds. When I send the same request through cURL…
Johannes Mols
  • 890
  • 1
  • 12
  • 35
6
votes
2 answers

How do I write an ASGI compliant middleware (while staying framework-agnostic)?

We're currently maintaining code written in several HTTP frameworks (Flask, aiohttp and FastAPI). Rewriting them so they all use the same framework is currently not feasible. There's some code that I'd like to share across those applications and…
exhuma
  • 20,071
  • 12
  • 90
  • 123
6
votes
3 answers

How to enable uvicorn to run asynchronously constructed app?

Given main.py: import asyncio async def new_app(): # Await some things. async def app(scope, receive, send): ... return app app = asyncio.run(new_app()) followed by: uvicorn main.app gives: RuntimeError: asyncio.run()…
Mario Ishac
  • 5,060
  • 3
  • 21
  • 52
6
votes
1 answer

Why does django-channels not connect to secure Websockets wss?

Lately I have been developing an app called(DBSF - don't be a sh***y friend), which functions a little bit like facebook, but it reminds you to interact with your friends once in a while. I've encountered a bug that I have been unable to fix for a…
Fabian Omobono
  • 81
  • 2
  • 13
6
votes
2 answers

What's the right procfile / requirements for heroku with django channels?

tl;dr - django channels app runs local with manage.py runserver but not on heroku. I'm new to django channels - trying to deploy a very basic django app using channels to heroku. I initially built the project using the standard django polls…
Krishna
  • 61
  • 1
  • 2
6
votes
1 answer

Django 3.0 — database connections are not closed after async tests

I use Django ORM inside async code. Everything works fine and all tests pass. However, DB connections do not close properly after tests. Here is an example: from asgiref.sync import sync_to_async, async_to_sync @sync_to_async def count_books(): …
Max Malysh
  • 29,384
  • 19
  • 111
  • 115
6
votes
1 answer

How to Configure NGINX to Serve ASGI from UNIX Socket?

I am unable to connect an application running on ASGI + Gunicorn through a Unix socket on NGINX on localhost via a docker container. Provided that I am in the docker container and run NGINX: /usr/sbin/nginx I can open http://localhost/api/v1/items…
5
votes
2 answers

How to stop a loop on shutdown in FastAPI?

I have a route / which started an endless loop (technically until the websocket is disconnected but in this simplified example it is truly endless). How do I stop this loop on shutdown: from fastapi import FastAPI import asyncio app =…
Sir l33tname
  • 4,026
  • 6
  • 38
  • 49
5
votes
1 answer

Too many db connections (django 4.x / ASGI)

I have deployed a django app (on ASGI using uvicorn) and getting a lot of OperationalError FATAL: sorry, too many clients already It seems that this is a known issue #33497 for django 4.x and ASGI, but I cant find anything on it (other than…
fekioh
  • 894
  • 2
  • 9
  • 22
1
2
3
14 15