[Twisted-Python] Re : executing .rpy in a thread

James Y Knight foom at fuhm.net
Tue Sep 16 16:28:38 EDT 2003


On Tuesday, September 16, 2003, at 03:10  PM, Itamar Shtull-Trauring 
wrote:

> Should be d.addCallback(lambda _: request.finish()) since it takes no
> arguments.
> However, this approach in general is wrong. Using Woven is probably a
> better way of dealing with this, since it handles Deferreds
> transparently.

What you *really* want to do is apply the patch I posted earlier that 
makes render handle deferreds properly, and then do:

---cut---
from twisted.web import server, resource, static, script
from twisted.internet import reactor
from twisted.internet import threads

def doLongPageGeneration():
      return "<html><b>H</b>ello, <b>W</b>orld!</html>"

class Simple(resource.Resource):
      isLeaf = True
      def render(self, request):
          return threads.deferToThread(doLongPageGeneration)

site = server.Site(Simple())
reactor.listenTCP(8080, site)

reactor.run()
---cut---

James





More information about the Twisted-Python mailing list