Async-sig April email@example.com
- 1 participants
- 1 discussions
Re-purposing WSGI standard, PEP 3333, for use in callback based async backends.
by TobiasHT 28 Apr '22
by TobiasHT 28 Apr '22
28 Apr '22
Asynchronous programming in python has become popular in the past few months. Quite a number of frameworks and servers have been developed to take advantage of this python feature. With the development of numerous such tools in python, a standard needed to be set to streamline their development by setting a common interface to implement, and hence the ASGI standard was born. The ASGI standard is holding up quite well when it comes to ease of implementation and general popularity. However, it imposes the use of coroutines in almost everything, which I feel is a design constraint in some way. PEP 3156 suggests that one can use asyncio with either callbacks or coroutines and does not favor one pattern over the other, but the continued use of only coroutines in many of the existing tools due to the constraint imposed by ASGI is limiting the use of the callback pattern, which is quite easier in my opinion, and achieves a similar level of concurrency. So my suggestion is to repurpose the existing WSGI standard, PEP 3333 in order to incorporate the aspect of callback based concurrency. I feel it would be much easier than redesigning the ASGI standard since WSGI doesn’t use coroutines in the first place. I assume it would also be easier for the existing WSGI based tools like Flask, Django, bottle and others to implement, and it would probably be much more efficient than their existing efforts to migrate to ASGI standard. It would also in a way bridge a gap between the async and sync worlds since this is one of the topics that gives us a headache. It’s evident that I have not thought everything through. I was just waiting for people’s reaction to this idea before I can proceed any further with it. One of the problems that this idea will face will be the conflict between WSGI and ASGI yet ASGI is trying to phase out WSGI. The other perhaps would be that many parts of asyncio, especially those connected to networks, are coroutines. Those are my thoughts however, I wonder what everyone else’s thoughts on this are.