|
|
|
|
|
by anentropic
3217 days ago
|
|
So what you're saying is it needs an 'async' version of the Django ORM for the example to work In other words what is really needed is an ORM that would allow you to write: source = await Source.objects.get(id=source_id)
await source.update()
(?) |
|
This leads to a sort of infectious need to make everything async as even a single non cooperating coroutine can bring the whole show to a halt. It's essentially the red vs blue function problem of Python. However, there is actually a nice alternative, gevent. gevent will monkey patch all functions in the standard library which would block, e.g. reading from a socket, attaching an implicit await to them. If the author has used gevent, the example Django code would actually work as expected, since the code would execute until the database connection was written to/read from and then immediately await.
Either way, async IO is still a somewhat tricky thing to understand and get right. It took writing a non blocking event loop with epoll in my case to really grok what was going on under the hood of something like asyncio.