[Twisted-Python] deferred TCP writes
itamar at itamarst.org
Tue Apr 18 14:00:53 EDT 2006
On Tue, 2006-04-18 at 10:44 -0700, Brian Granger wrote:
> I have run into this issue as well when trying to order different
> writes and make code run _after_ a write was completed. I ended up
> calling my code using deferToThread and putting in time.sleep calls to
> make sure things got ordered correctly. Ugly hack though.
Eeeeew. Don't do that.
> I echo the question: why doesn't write return a deferred? Surely
> there are times you want to trigger events on the completion of a
This is (more or less) what the producer API is for. Register a
IConsumer with transport.registerProducer and you will get callbacks
telling you when the transport buffer becomes empty or full.
Returning Deferred from every transport.write would make everything
rather slow... a wrapper that does this could be probably be written
using the producer/consumer API.
More information about the Twisted-Python