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

Ray Price rprice at collegenet.com
Wed Sep 17 18:16:46 MDT 2003


How would I create a .tap file to execute the example below?

Ray 



On Tue, 2003-09-16 at 12:20, Bob Ippolito wrote:
> On Tuesday, Sep 16, 2003, at 14:38 America/New_York, Jerome Jushima 
> wrote:
> 
> > With the help of your hint I have come up with the following code. For
> > simplicity's sake I don't use .rpys here since it shouldn't change the 
> > approach.
> > What happens when I run this code and open the servers root in a 
> > webbrowser is
> > that I get a page saying "NOT_DONE_YET." Also when I get rid of the
> > quotation marks in the return statement it does not seem to work. 
> > Python just tells
> > me that it does not know NOT_DONE_YET.
> 
> This is how you want to do it, there should be no surprises with this 
> approach (it handles failures, logs to stdout):
> 
> from twisted.web import server, resource, static, script
> from twisted.internet import reactor, threads
> from twisted.python import log
> import sys
> 
> def doLongPageGeneration(request):
>      # you *could* inspect the request object if you needed to from here
>      # but I wouldn't *change* it from this thread!
>      return "<html><b>H</b>ello, <b>W</b>orld! - Your user agent is 
> %s</html>" % request.getHeader('user-agent')
> 
> def writeRequestAndFinish(data, request):
>      request.write(data)
>      request.finish()
> 
> class Simple(resource.Resource):
>      isLeaf = True
>      def render(self, request):
>          threads.deferToThread(doLongPageGeneration, 
> request).addCallback(writeRequestAndFinish, 
> request).addErrback(request.processingFailed)
>          return server.NOT_DONE_YET
> 
> site = server.Site(Simple())
> reactor.listenTCP(8080, site)
> # I'm not sure if this is strictly necessary, but it seems like a good 
> idea.
> reactor.initThreads()
> log.startLogging(sys.stdout)
> reactor.run()
> 
> 
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python






More information about the Twisted-Python mailing list