【发布时间】:2011-06-04 21:18:53
【问题描述】:
我是一个真正的编码n00b,如果这是一个简单或基本的问题,我们深表歉意。
我正在使用 Python、Webapp、Appengine 进行编码。
我的问题是,我写完页面后可以继续工作吗?这是做某事的最佳方式吗?基本上,当有人在我的网站 (www.7bks.com) 上创建列表时,我想继续工作一点,对他们刚刚选择的书籍进行一些“后期处理”。
目前我有这样的东西(伪代码!)
class InputList(webapp.RequestHandler):
def post(self):
#get books data from the post and put in datastore
list = List()
list = self.request.get('books')
list.put()
#redirect the user to the new list
self.redirect("http://www.7bks.com/list/&s" % list.id)
现在,我想对列表中的每本书进行一些缓慢(涉及 API 调用)的后处理。我不想减慢重定向用户和生成列表页面的速度,因为我的后处理不会直接影响列表页面。那我可以这样做吗?
class InputList(webapp.RequestHandler):
def post(self):
#get books data from the post and put in datastore
list = List()
list = self.request.get('books')
list.put()
#redirect the user to the new list
self.redirect("http://www.7bks.com/list/&s" % list.id)
#carry on working behind the scenes independently of the user
for book in list:
data = heavyprocessing(book)
这会导致我的应用程序有效地为重定向提供服务,然后继续在幕后工作吗?
有没有更好的方法来做到这一点?我知道我可以使用 CRON,但我希望在创建列表后不久就获得这些繁重的处理数据,但不是立即。感觉 Cron 可能不是正确的答案(除非我有一个 CRON 脚本每分钟左右运行一次并检查要处理的新书?)
我知道这并不是我的问题,但我想不出一个好的表达方式。我确信这种事情有一些标准术语,但我不知道它是什么。谢谢:)
汤姆
【问题讨论】:
标签: python google-app-engine web-applications asynchronous