【发布时间】:2011-09-07 11:46:56
【问题描述】:
我是谷歌应用引擎中任务队列 API 的新手。我创建了一个新队列并使用 taskqueue.add() 函数在其中添加了一个任务。我已经定义了任务的 url,并写下了任务 url 的逻辑。但是该任务不会异步发生,因为应用程序正在等待任务完成,然后在 taskqueue.add() 函数之后继续执行语句。如何使任务异步?对此问题的任何帮助表示赞赏。
代码如下所示
class botinitiate(webapp.RequestHandler):
def get(self):
# some more statements here
template_values = {'token': token,
'me': user.user_id()
}
taskqueue.add(url='/autobot', params={'key':game_key},queue_name='autobot')
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))
class autobot(webapp.RequestHandler):
def post(self):
# task logic goes here
application = webapp.WSGIApplication([('/botinitiate',botinitiate),('/autobot',autobot)],debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
谢谢
【问题讨论】:
-
您如何确认应用正在等待任务完成以发送响应?
-
使用appengine的日志。它在继续执行 taskqueue.add() 之后的语句之前完成任务
-
来自启动任务的处理程序和任务本身的示例代码会很有帮助。
-
我已经在消息中添加了代码
标签: python google-app-engine task-queue