title: Twisted async request processing
body: <p>How can I do async request processing in Twisted like in Node.js?</p>
  
  <p>I wrote sample with Twisted, but my app still waited an answer from long operation(I emulate this with time.sleep).</p>
  
  <p>Also I don't understand how can I use reactor.callLater correct.</p>
  
  <p>This is my sample of twisted app.</p>
  
  <pre><code>
  from twisted.web import server
  from twisted.web.resource import Resource
  from twisted.internet import reactor
  from twisted.internet.defer import Deferred
  import time
  
  class Hello(Resource):
      def getChild(self, name, request):
          if name == '':
              return self
          print name
          return Resource.getChild(self, name, request)
  
      def render_GET(self, req):
          d = Deferred()
          reactor.callLater(2, d.callback, None)
          d.addCallback(lambda _: self.say_hi(req))
          return server.NOT_DONE_YET
  
      def say_hi(self, req):
          req.setHeader("content-type", "text/html")
          time.sleep(5)
          req.write("hello!")
          req.finish()
  
  class Hello2(Resource):
      isLeaf = True
      def render_GET(self, req):
          req.setHeader("content-type", "text/html")
          return "hello2!"
  
  root = Hello()
  root.putChild("2", Hello2())
  reactor.listenTCP(8080, server.Site(root))
  reactor.run()
  </code></pre>
  
  <p>Edit: Now question is how to write a sync code? Please example.</p>