[Twisted-Python] connection pool
Tjerk.Kusters at imtech.nl
Tjerk.Kusters at imtech.nl
Thu Jan 17 04:42:34 EST 2008
>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
More information about the Twisted-Python
mailing list