hi
as you know python interactive shell can be called as python -m asyncio which alows awaiting in the shell
but django doesn’t seems to support that, which makes testing async stuff hard
is there any plans to add this feature?
is is feasible?
I spent some time trying to figure out how to add asyncio as a supported interface and my conclusion is that there isn’t a way to drop into an asyncio-enabled shell from an existing python process. There definitely isn’t a supported mechanism (maybe we should file an upstream issue against python to enable that) but even if we exclude official and try and use the existing interface unofficially it doesn’t work without crazy hacks that should not be upstreamed to Django.
What we could do is duplicate the existing cpython implementation but I’m more in favor of getting a “real” interface landed to cpython and then just calling that.
I believe you need to use one of the alternative shells such as ipython to do this as mentioned above:
Python 3.12.6 (main, Sep 10 2024, 00:05:17) [GCC 11.4.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.26.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import asyncio
In [2]: async def a():
...: return 1
...:
In [3]: await a()
Out[3]: 1
In [4]: