Movatterモバイル変換
[0]ホーム
[Python-ideas] Are there asynchronous generators?
Paul Moorep.f.moore at gmail.com
Thu Jul 2 11:57:40 CEST 2015
On 1 July 2015 at 06:56, Nick Coghlan <ncoghlan at gmail.com> wrote:> For folks that primarily deal with algorithmic problems where inputs> are converted to outputs, the event driven model addresses a kind of> problem that *they don't have*, so it can seem entirely pointless.> However, there really are significant categories of problems (such as> network service development) where the event driven model is a> genuinely superior design tool. Like array oriented programming (and> even object-oriented and functional programming), the benefits can> unfortunately be hard to explain to folks that haven't personally> experienced the problems these tools address, so folks end up having> to take it on faith that we're applying the "Complex is better than> complicated" line from the Zen of Python when introducing new> modelling techniques into the core language.Hmm, I see what you're getting at here, but my "event driven model"background is with GUI event loops, not with event driven IO. Theasync/await approach still gives me problems, because I can't map thedetails of the approach onto the problem domain I'm familiar with.What I can't quite work out is whether that's simply because asynciois fundamentally designed around the IO problem (the module namesuggests that might be the case, but a lot of the module contentaround tasks, etc, doesn't seem to be), and so doesn't offer any sortof mental model for understanding how GUI event loop code based onasync/await would work, or if it's because the async/await designgenuinely doesn't map well onto GUI event loop problems.I've been poking in the background at trying to decouple the "IO"aspects of asyncio from the "general" ones, but honestly, I'm notgetting very far yet. I think what I need to do is to work out how towrite a GUI event loop that drives async/await style coroutines, andsee if that helps me understand the model better. But there aren'tmany examples of event loops around to work from (the asyncio one ispretty complex, and it's hard to know how much of that complexity isneeded, and how much is because it was developed before async/awaitwere available).So while I agree that if you don't need an event driven model, it canseem like pointless complexity, I *also* think that the pure callbackapproach to event driven code is what feels "obvious" to most people.It's maybe not the easiest model to code with, but it is the easiestone to think about - and mentally making the link between callbacksand async/await isn't straightforward. So even though people canunderstand event-driven problems, they can't, without experience, seehow async/await *addresses* that problem.Paul
More information about the Python-ideasmailing list
[8]ページ先頭