daily pastebin goal
64%
SHARE
TWEET

Untitled

a guest May 16th, 2018 108 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from twisted.web import server, resource
  2. from twisted.internet import reactor, threads
  3.  
  4. import time
  5.  
  6. class Simple(resource.Resource):
  7.     isLeaf = True
  8.     def render_GET(self, request):
  9.    
  10.     d = threads.deferToThread(self.loooong_rendering, request)
  11.     d.addCallback(self.printResult)
  12.  
  13.     return server.NOT_DONE_YET
  14.  
  15.     def loooong_rendering(self, request):
  16.     time.sleep(5)
  17.  
  18.         return (request, "<html>Hello, world!</html>")
  19.  
  20.     def printResult(self, result):
  21.     request, html = result
  22.    
  23.     request.write(html)
  24.     request.finish()
  25.  
  26. site = server.Site(Simple())
  27. reactor.listenTCP(8081, site)
  28. reactor.run()
RAW Paste Data
Top