[issue9693] asynchat push_callable() patch

Antoine Pitrou report at bugs.python.org
Wed Sep 1 00:23:04 CEST 2010


Antoine Pitrou <pitrou at free.fr> added the comment:

> > - why override __bool__??
> 
> I did that for performance.
> Considering that initiate_send() method is called many times, and that
> it is almost always used to send data rather than firing functions I
> wanted to avoid to call isinstance(first, _Callable) (or
> hasattr(first,  '__call__')) on every loop.

This looks hackish... You should at least make the purpose very clear in
comments to the code.
Also, really, isinstance(..., _Callable) is better than the hasattr()
call, IMO.

> The API follows the exact same approach as push(),
> push_with_producer() and close_when_done() methods.
> It adds "something" to a fifo and that "something" will be processed
> (called) only when the previous producers are exhausted, respecting
> the order of what has been "pushed" first and later.
> This is different than a deferred.

Well, a deferred would be fired when a given piece of data has been sent
(or failed to send, in which case the errback would be run rather than
the callback). This is in the end equivalent, since I suppose the send
queue is sequential and never gets reordered.

In any case, I guess it's too late to change the overall design. I just
wanted to point out that the Deferred concept unified a lot of use cases
under a simple convenient abstraction. It avoids having to define ad hoc
methods such as push_callable().

> Something similar to Twisted deferreds is this:
> http://bugs.python.org/issue1641

This has nothing to do with Deferreds actually :)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9693>
_______________________________________


More information about the Python-bugs-list mailing list