Probably this was a bad idea to use ASGI vs WSGI as the title for this post. Because ASGI (Asynchronous Server Gateway Interface ) is WSGI 's (Web Server Gateway Interface) spiritual successor. Django's latest release includes support for ASGI. Let see what synchronous and asynchronous tasks do with these terms. Synchronous tasks do follow a sequence execution of the tasks by having synchronization with its previous request. WSGI simply follows the synchronous structure by returning a response to the input request.
When it comes to long-living requests, for example a socket connection, this really sucks!
This drawback is eliminated by using ASGI which creates a multiple callable Interface. This helps to trigger multiple requests.
#WSGI example
def application(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
return b'Hello, Gspace\n'
It' returns for the input request but does not wait for others.
Now let's do this using ASGI.
async def application(scope, receive, send):
event = await receive()
...
await send({"type": "websocket.send", ...})
#Triggers multiple events
Here scope contains information about the incoming request, receive contains events from the client and send contains events to send to the client.
communication takes place as a python dict.
This can also listen to external triggers.
That's it for now!
Also read Separate vocals and background Music from an audio file using Python
comment 0 Comments
more_vert