Hi Folks .. I'm not entirely a newbie a python and twisted, but I have come to the point where I need a bit more expertise on this topic, so I am hoping that I have come to the right place .. What I'm hoping, that you folks can help out with a minor problem that I am having with the twistd reactor class and/or the callLater function I have been using a reactor.callLater function to schedule an event that happens in the reactor to send out a heartbeat type message at regular intervals .. This works great ! However, it appears to me that the self.sendLine(msg) and or the self.transport.write(msg) writing functions are blocked functions waiting for a reactor event to occur at a future scheduled time before acutally flushing out the internal write buffers .. I am currently using the twistd protocol factory to create a custom protocol to communicate between a server and client, which up until now has not been a real concern, but I am trying to improve the preformance and turn around time between the client and server and this blocking operation is a major source of unneeded delay .. My problem is that I have scheduled heartbeat events that I want to send to the server .. as well as the non scheduled events that I want to go to the server imediately .. I have been scouring the various python/twistd document sites, but to no avial, on all of the sites that I have seen, the method used have all done the same thing , by re-scheduling something into the future with a reactor.callLater () function, which causes a delayed write to occur .. not a problem for something that is 1 or 2 second s in the furture, but it is a serious problem when the next event is 120 seconds away .. I have tried using a self.transport.write(msg) function, but the actual communication still seems to be buffered and stuck waiting for the scheduled reactor event .. What I think I need is something similar to self.transport.flush() which would flush out the write buffers on demand, but does not seen to exist .. I am hoping that someone has faced the same/similar stituation and give me some guidance and/or to point me in the correct direction .. Thanks for any help you can offer .. Cheers Dave Watson
On 01:12 am, david.watson@windriver.com wrote:
Hi Folks ..
I'm not entirely a newbie a python and twisted, but I have come to the point where I need a bit more expertise on this topic, so I am hoping that I have come to the right place ..
What I'm hoping, that you folks can help out with a minor problem that I am having with the twistd reactor class and/or the callLater function
I have been using a reactor.callLater function to schedule an event that happens in the reactor to send out a heartbeat type message at regular intervals .. This works great !
However, it appears to me that the self.sendLine(msg) and or the self.transport.write(msg) writing functions are blocked functions waiting for a reactor event to occur at a future scheduled time before acutally flushing out the internal write buffers ..
This isn't the intended behavior. The most common mistake which leads to it is trying to use Twisted APIs such as these from a different thread than the one where reactor.run() was called. The only thread- safe Twisted API is reactor.callFromThread. You didn't say anything about threads in your post, so I don't know if this is the problem you're having, but since it's so common I thought I'd mention it. Jean-Paul
Hi Jean-Paul .. Thanks for your response .. I think your correct, I got an earlier email from Andrew, and he pointed me in the same direction .. I am investigating this new info now and I think that this appears to be the problem .. Thanks for your help .. Cheers Dave W. -----Original Message----- From: twisted-web-bounces@twistedmatrix.com [mailto:twisted-web-bounces@twistedmatrix.com] On Behalf Of exarkun@twistedmatrix.com Sent: Wednesday, February 24, 2010 9:34 AM To: Twisted Web World Subject: Re: [Twisted-web] Reactor events help request .. On 01:12 am, david.watson@windriver.com wrote:
Hi Folks ..
I'm not entirely a newbie a python and twisted, but I have come to the point where I need a bit more expertise on this topic, so I am hoping that I have come to the right place ..
What I'm hoping, that you folks can help out with a minor problem that I am having with the twistd reactor class and/or the callLater function
I have been using a reactor.callLater function to schedule an event that happens in the reactor to send out a heartbeat type message at regular intervals .. This works great !
However, it appears to me that the self.sendLine(msg) and or the self.transport.write(msg) writing functions are blocked functions waiting for a reactor event to occur at a future scheduled time before acutally flushing out the internal write buffers ..
This isn't the intended behavior. The most common mistake which leads to it is trying to use Twisted APIs such as these from a different thread than the one where reactor.run() was called. The only thread- safe Twisted API is reactor.callFromThread. You didn't say anything about threads in your post, so I don't know if this is the problem you're having, but since it's so common I thought I'd mention it. Jean-Paul _______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
participants (2)
-
exarkun@twistedmatrix.com
-
Watson, David