[Twisted-Python] connection pool

Christian Simms christian.simms at gmail.com
Wed Jan 16 10:48:30 EST 2008

On Jan 16, 2008 8:48 AM,  <Tjerk.Kusters at imtech.nl> wrote:
> Hello,
> I have build a webserver with Twisted 2.4 with imports of the following:
>  from twisted.web import resource, static, server, twcgi
>  from twisted.internet import reactor
> I'm adding several mods as child to the root with:
>  root = static.File(settings.getSetting("html_directory"))
>  root.putChild(mods.getPath(), mods
> The mods are classes like
>  class module(resource.Resource):
>    def render_GET(self, request):
>       # do something
> The reactor is started as:
>  reactor.listenTCP(_port, server.Site(root))
>  reactor.run( )
> Some of the GET request in the mods can take some time to complete. In the
> current situation other request to the server have to wait on this request.
> Is it possible to make soms kind of a thread/connection pool so that more
> then one request can be handled at the same time?
> Regards,
> Tjerk
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Yes it is possible to use a thread pool, in fact twisted comes with
one. However, how you use it depends on what is taking so long for

- if it's database calls then consider using twisted.enterprise.adbapi
- http://twistedmatrix.com/projects/core/documentation/howto/enterprise.html

- if it's python code taking so long then consider breaking your code
into shorter snippets that yield control back to twisted periodically
so that other requests don't get ignored

- if it's network code then make sure you're using Deferred's properly
- http://twistedmatrix.com/projects/core/documentation/howto/defer.html

Hope that helps.


More information about the Twisted-Python mailing list