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
Tjerk.Kusters@imtech.nl wrote:
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?
That wouldn't be very twisted :). Ideally your "# do something" code could quickly return a deferred which would fire when the result is ready. (I think it's a bit more complicated than just 'return my_deferred', but not much.) If the requests are spending time waiting for database requests, for example, you could use a non-blocking deferred API to the database. Worst case, if the delay is due to something that you really need to multi-thread, you could use t.i.threads.deferToThread on just that section. Then twisted would use a thread pool for the parts that need it and connect the rest of your code into the deferred event style.
participants (2)
-
Drew Perttula
-
Tjerk.Kusters@imtech.nl