2 ms·
I get what you're saying, that the docs dont really follow an overarching theme. Thankfully, stackoverflow fills in the rest. > I can't understand what the au
by digler999 10y ago
I get what you're saying, that the docs dont really follow an overarching theme. Thankfully, stackoverflow fills in the rest.
> I can't understand what the authors/developers were trying to achieve when writing it.
I can't speak for them, but event-driven designs are a great alternative to procedural polling / event loop designs. I am not sure, but I think there's a relationship to the functional programming style where you say "when there's data, do this to it". So I think what they're trying to accomplish is to enable FP paradigms in python. You could write a coroutine that says "yield until there's data, when there is, transform it".
I used it with zeromq [1] to route messages between a few C++ programs that all work together. So my python program is a "supervisor" task that sends heartbeat messages to my binary programs over zeromq. Asyncio is handy for timing the heartbeats (because you can say "in 2 seconds, do this") and reading the message queue. I also hooked it up to inotify, so I can do "echo SOME_COMMAND > command.txt" and as soon as command.txt is written to, my supervisor gets a notification, reads the file, and processes the command. I almost lost my sanity to get it working, but once I got it, I really like it. One tip though, dont try to mix async and sync programming. Go big or stay home.
[1] http://zeromq.org/ http://zeromq.org/