我可以在App Engine中使用Python创建线程吗?
这段代码能在Google App Engine中创建线程吗?如果不能,为什么呢?
class MyThread(threading.Thread):
def __init__(self,threadname):
threading.Thread.__init__(self, name=threadname)
def run(self,request):
log=LogText()
log.content=request.POST.get('content',None)
log.put()
def Log(request):
thr = MyThread('haha')
thr.run(request)
return HttpResponse('')
1 个回答
2
App Engine不允许你创建新的线程,这可能是因为它的主要目标是帮助你构建简单的请求-响应应用,而线程通常被认为不是“简单”的东西。
对于一个应用来说,管理线程以防止滥用(无论是故意还是无意)会非常困难,甚至是不可能的,所以App Engine干脆就不允许使用线程。