[Twisted-Python] Really Basic clarification on defers

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Wed Aug 5 11:17:53 EDT 2009

On 09:33 am, johnaherne at rocs.co.uk wrote:
>On Wed, Aug 5, 2009 at 12:14 AM, Johann Borck 
><johann.borck at densedata.com>wrote:
>Sendline is not blocking so as you say we can avoid the use of 
>deferreds and
>continue to use sendline directly.

LineReceiver.sendLine is not blocking, correct.  However, your statement
implies that if it were blocking, you could use Deferreds to address 
problem.  This is incorrect.  Deferreds do not make blocking APIs into
non-blocking APIs.
>Our option 3 using defertothread does use sendline from the thread. 
>response implies that is OK since you say defertothread is threadsafe. 
>you really mean that.

deferToThread is not thread-safe: you may only call it from the reactor 
(the thread in which you called reactor.run).

Since deferToThread runs the function you pass to it in a non-reactor 
you may not use any non-thread-safe Twisted APIs in the function you 
pass to
>Once again thanks for a very good response. That has cleared up a lot 
>I suppose it would help if there was a paragraph at the start of the 
>documentation detailing what you have just said. So when they start on
>deferreds you have some sort of context in which to interpret what is 

A significant effort is presently underway to improve the documentation 
Deferreds.  Any specific feedback you have about it would be much 


More information about the Twisted-Python mailing list