[Twisted-Python] does setTcpNoDelay() not work?

Jean-Paul Calderone exarkun at divmod.com
Mon Aug 11 14:22:31 EDT 2008

On Mon, 11 Aug 2008 20:18:43 +0200, Gabriel Rossetti <gabriel.rossetti at arimaz.com> wrote:
>Jean-Paul Calderone wrote:
>>On Mon, 11 Aug 2008 19:13:56 +0200, Gabriel Rossetti 
>><gabriel.rossetti at arimaz.com> wrote:
>>>Gabriel Rossetti wrote:
>>>>I'm needing to send small packets to update a progress bar. My update 
>>>>msgs were all being sent in big packets, so I tried setting 
>>>>setTcpNoDelay() in connectionMade() but it doesn't change anything, is it 
>>>>Thank you,
>>>I an using code that I wrote using threads.deferToThread(), I wondered if 
>>>it was blocking the reactor maybe, so I tried just using a plain 
>>>deferToThread() call. Here's the code (without all the protocol stuff, 
>>>it's executed when data come in.
>>>    def loop(self):
>>>        import time
>>>        m = utils.createMessage("toto", "hello")
>>>        while(True):
>>>            print "Sending %s" % m.toXml()
>>>            self.sendMessage(m)
>>>            print "Sent!"
>>>            time.sleep(2)
>>>the TCP no delay option is turned on like I said before, the weird thing 
>>>is that I have the same thing, all my msgs get sent in big blocks. Either 
>>>the TCP no delay doesn't work, or the reactor is getting tied up. I don' t 
>>>get it since I'm running the blocking code in a thread, the reactor should 
>>>have nothing to do.
>>Since you didn't include the definition of `sendMessage´, it's hard to say
>>what's really going on here.  However, my guess is that you're calling the
>>transport.write method in a non-reactor thread, which is not allowed.
>>If this isn't the case, including a full, minimal example in your next
>>message would be a good idea. :)
>Yes, self.sendMessage() calls transport.write. So there's no way of sending 
>msgs from a non-reactor thread, even if it has a reference to the protocol?

There is a way.  The way is to use reactor.callFromThread to schedule a
function to be called in the reactor thread.

eg, reactor.callFromThread(self.sendMessage)


More information about the Twisted-Python mailing list