[Twisted-Python] Twisted TCP Window Full due to time-consuming fuction
p.mayers at imperial.ac.uk
Wed Mar 7 04:46:54 EST 2012
On 03/07/2012 08:37 AM, Peng Xiao -X (penxiao - Digital China at Cisco)
> Because the function of parseBuffer is a litter time consuming, so the
> receive buffer is full sometimes.
The answer is: don't do that.
If parseBuffer is expensive, you will block the reactor, which you must
You have two options:
1. Run the work in a thread with "deferToThread". Note: you MUST NOT
call any reactor APIs from the thread, except reactor.callFromThread
2. Break the work up into small pieces, and run it incrementally. See
twisted.internet.task.coiterate for example; this allows you to run any
iterator, such as a generator, and get the result as a deferred.
More information about the Twisted-Python