[Python-ideas] asyncore: included batteries don't fit

Antoine Pitrou solipsis at pitrou.net
Fri Oct 12 09:14:54 CEST 2012


On Fri, 12 Oct 2012 00:29:05 -0400
Devin Jeanpierre <jeanpierreda at gmail.com>
wrote:
> 
> These are the examples I remember mentioned in the talk:
> 
> - http://api.jquery.com/category/deferred-object/ (not very twistedish
> at all, ill-liked by the speaker)
> - http://mochi.github.com/mochikit/doc/html/MochiKit/Async.html (maybe
> not a good example, mochikit tries to be "python in JS")
> - http://dojotoolkit.org/reference-guide/1.8/dojo/Deferred.html
> - https://github.com/kriskowal/q (also includes an explanation of why
> the author likes deferreds)

Mochikit has been dead for years.

As for the others, just because they are called "Deferred" doesn't mean
they are the same thing. None of them seems to look like Twisted's
Deferred abstraction.

> The reason explicit non-deferred callbacks are involved in Twisted is
> because of situations in which deferreds are not present, because of
> past history in Twisted. It is not at all a limitation of deferreds or
> something futures are better at, best as I'm aware.

A Deferred can only be called once, but a dataReceived method can be
called any number of times. So you can't use a Deferred for
dataReceived unless you introduce significant hackery.

> Anyway, one big issue is that generator coroutines can't really
> effectively replace callbacks everywhere. Consider the GUI button
> example you gave. How do you write that as a coroutine?
> 
> I can see it being written like this:
> 
>     def mycoroutine(gui):
>         while True:
>             clickevent = yield gui.mybutton1.on_click()
>             # handle clickevent
> 
> But that's probably worse than using callbacks.

Agreed. And that's precisely because your GUI button handler is a
dataReceived-alike :-)

Regards

Antoine.


-- 
Software development and contracting: http://pro.pitrou.net





More information about the Python-ideas mailing list