[Twisted-Python] connection pool

Jean-Paul Calderone exarkun at divmod.com
Thu Jan 17 06:17:52 EST 2008


On Thu, 17 Jan 2008 10:42:34 +0100, tjerk.kusters at 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




More information about the Twisted-Python mailing list