下面是我的基本處理程序。我只想服務器映像,並在請求完成後,我想寫入到redis,但是當我運行下面的代碼時,on_finish不會被調用。Twisted Cyclone - 如何在請求完成後寫入redis
import cyclone.web
import cyclone.redis
from twisted.internet import defer
from twisted.internet import reactor
tt = cyclone.redis.lazyConnectionPool()
class PixelHandler(cyclone.web.RequestHandler):
@cyclone.web.asynchronous
def get(self):
qs = qs_decode(self.request.query)
self.set_header('Content-Type', 'image/gif')
self.write(pixel)
redisPixelWrite(remote_ip)
#self.finish()
def on_finish(self):
t = yield tt.multi()
yield t.set('key', 'value')
r = yield t.commit()
print "commit=", repr(r)