[Twisted-Python] How to accept connections faster

Mike C. Fletcher mcfletch at rogers.com
Wed Mar 16 03:41:43 MST 2005


Danny, Twisted is an asynchronous system.  You *cannot* use that kind of 
blocking delay tactic in Twisted without totally destroying Twisted's 
functionality:

>         for i in range(10000000):
>             pass
>         print "Looping done."
>         self.transport.loseConnection()
>
should have been something like:

    def closeInABit( ):
        self.transport.loseConnection()
    reactor.callLater( 2, closeInABit ) # call after 2 seconds

You'll want to read up on asynchronous programming (e.g. on the Twisted 
web site) to get a feel for how this model of programming networked apps 
works.

Good luck,
Mike


Sinang, Danny wrote:

> Hello.
>  
> I ran the (Twisted) server code below and it accepts a client socket 
> connection every 1.3 seconds. The equivalent Synchronous socket code 
> accepts one every 2 seconds.
>  
> Can anyone here suggest any code improvements for my Twisted server to 
> accept connections faster ?
>  
> I've include the Synchronous socket server code and the client 
> generator code below as well.
>  

...
________________________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com
                              PyCon is coming...





More information about the Twisted-Python mailing list