|
|
|
|
|
by lilbobbytables
3218 days ago
|
|
> That seems wrong. I should be able to run normal Python code as async, right? No, that is not the case.
To better understand this you should look at an async library, like https://github.com/aio-libs/aiohttp
Look at what it actually calls all the way down under the hood. 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 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. 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. |
|
In other words what is really needed is an ORM that would allow you to write:
(?)