Google Application Engine解决方法上的Python线程(或等效线程)? [英] Python Threads (or their equivalent) on Google Application Engine Workaround?

查看:78
本文介绍了Google Application Engine解决方法上的Python线程(或等效线程)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个执行以下操作的Google App Engine应用程序:

I want to make a Google App Engine app that does the following:

  1. 客户端发出异步http请求
  2. 服务器开始处理该请求
  3. 客户端发出ajax http请求以获取进度

问题在于服务器处理(第2步)可能需要30秒钟以上的时间.

The problem is that the server processing (step #2) may take more than 30 seconds.

我知道您无法在Google Application Engine上使用线程,并且所有任务必须在30秒内完成,否则它们将被关闭.有什么办法可以解决这个问题?

I know that you can't have threads on Google Application Engine and that all tasks must complete within 30 seconds or they get shut down. Is there some way to work around this?

另外,我正在使用python-django作为后端.

Also, I'm using python-django as a backend.

推荐答案

您将要使用延迟的任务. deferred API大大简化了任务队列的工作.

You'll want to use the Task Queue API, probably via deferred tasks. The deferred API makes working with Task Queues dramatically simpler.

从本质上讲,您将需要生成一个任务来开始处理.该任务应捕获DeadlineExceeded异常并重新计划自身(再次通过deferred API)以继续处理.这要求您的任务能够跟踪自己的进度.他们还可以在Memcache中更新自己的状态,您可以使用其编写检查任务状态的视图.然后可以通过Ajax对该视图进行轮询.

Essentially, you'll want to spawn a task to start the processing. That task should catch DeadlineExceeded exceptions and reschedule itself (again via the deferred API) to continue processing. This requires that your tasks be able to keep track of their own progress. They can also update their own status in memcache, which you can use to write a view that checks a task's status. That view can then be polled via Ajax.

这篇关于Google Application Engine解决方法上的Python线程(或等效线程)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆