> That seems wrong. I should be able to run normal Python code as async, right?<p>No, that is not the case.
To better understand this you should look at an async library, like <a href="https://github.com/aio-libs/aiohttp" rel="nofollow">https://github.com/aio-libs/aiohttp</a>
Look at what it actually calls all the way down under the hood.<p>If it were as simple as adding `asyncio.sleep(0)`, then that library seems as though it would have been much easier to write. :P<p>Just look at the code you posted at the end, it actually runs faster synchronously, without `asyncio.sleep(0)`.
The sleep is what happens async, not the print statements, therefore, all you're doing is introducing delay.<p>Similarly, the Django ORM DB calls you make in the other examples are all still happening synchronously. However, you're just adding a delay that causes them to get picked off in an inconsistent order.
For OP's case, I wouldn't have jumped to async, but instead either to multithreading or multiprocessing. Pool().map makes this really trivial. Taking their example, and tweaking it slightly:<p><pre><code> import requests
from multiprocessing import Pool
def fetch_things():
pool = Pool() # defaults to number of CPUs
urls = ['https://example.com/api/object/1',
'https://example.com/api/object/2',
'https://example.com/api/object/3']
return pool.map(requests.get, urls)
print(fetch_things())
</code></pre>
Output (because those URLs are nonsense...):<p><pre><code> [<Response [404]>, <Response [404]>, <Response [404]>]
</code></pre>
It's just as easy to do it in threading. Just switch that "from multiprocessing import Pool" with "from multiprocessing.dummy import Pool"
I'm sure someone will correct me here, but in my experience, Pythons Async model is a cluster-fuck.<p>It feels very much like it was just kind of thrown in to keep up with the trends, without any thought as to whether it made sense or whether it was the most "Pythonic" way of implementing it.
Async IO libraries tend to make very simple things very complicated. I spent half a day trying to use Boost.Asio to receive a UDP frame before giving up and using QUdpSocket (which took less that 5 minutes).<p>Agreed with the author's sentiment of feeling stupid.
coroutines are tacos, and monads are burritos. Repeat after me.<p>ps: for the author, my only theory about the 0s sleep is that coroutines aren't preempted like threads, they use collaborative concurrency, so unless they actually say "ok I agree to pause now and let others do something" well the interpreter will evaluate all the instructions until completion. My 2 cents