我的代码如下所示:
... # class Site(Resource)
def render_POST(self,request)
otherclass.doAssync(request.args)
print '1'
return "done" #that returns the HTTP response, always the same.
...
def doAssync(self,msg):
d = defer.Deferred()
reactor.callLater(0,self.doStuff,d,msg)
d.addCallback(self.sucess)
def doStuff(self,d,msg):
# do some stuff
time.sleep(2) #just for example
d.callback('ok')
def sucess(msg):
print msg
输出:
1
行
到目前为止,一切都很好,但是 HTTP 响应(返回“完成”)仅在延迟(time.sleep(2))之后发生。我可以这么说,因为浏览器会保持“加载”2 秒。
我究竟做错了什么?