Re: [Twisted-Python] connection pool

making a blocking call (CORBA) inside the reactor loop, which prevents other connections to happen. If you don't manage to find an asynchronous CORBA client, you should do the call inside a thread, using reactor.callInThread for example.
However, it would be easier to help you with an example of your code or a more detailed description of your problem.
I have create a small example program to show my problem. from twisted.web import resource, static, server from twisted.internet import reactor import datetime, time class module_1(resource.Resource): def render_GET(self, request): request.write("module 1<br>") request.write(datetime.datetime.today().strftime("%Y-%m-%dT%H:%M:%S")) return "" def doWork(): # perform call which can take some seconds to return time.sleep(10) return "ready" class module_2(resource.Resource): def render_GET(self, request): request.write("module 2<br>") request.write(doWork()) return "" root = static.File("d:/www") root.putChild("module1", module_1()) root.putChild("module2", module_2()) reactor.listenTCP(8900, server.Site(root)) print "Reactor run" reactor.run( ) When I do request http://localhost:8900/module2 an other request to http://localhost:8900/module1 has to wait on the first one to finish. So the doWork is blocking the reactor and I should perform the work in a thread. But my question is then: how can I perform the render_GET of module_2 in a thread and still return the answer back to the webpage? Hope this gives enough details on the situation. Regards, Tjerk

On Thu, 17 Jan 2008 10:42:34 +0100, tjerk.kusters@imtech.nl wrote:
making a blocking call (CORBA) inside the reactor loop, which prevents other connections to happen. If you don't manage to find an asynchronous CORBA client, you should do the call inside a thread, using reactor.callInThread for example.
However, it would be easier to help you with an example of your code or a more detailed description of your problem.
I have create a small example program to show my problem.
[snip]
class module_2(resource.Resource): def render_GET(self, request): request.write("module 2<br>") request.write(doWork()) return ""
At some point (perhaps the next version of Twisted, perhaps not), render_GET will support Deferreds so this will get easier. However, until then, you can still have asynchronous render_GET implementations. You just have to use NOT_DONE_YET. For example, from twisted.web.resource import NOT_DONE_YET, Resource from twisted.internet.defer import Deferred from twisted.internet import reactor class SlowResource(Resource): def render_GET(self, request): d = Deferred() def finishedSlowThing(result): request.write(result) request.finish() reactor.callLater(3, d.callback, "the result") return NOT_DONE_YET Hope this helps, Jean-Paul
participants (2)
-
Jean-Paul Calderone
-
Tjerk.Kusters@imtech.nl