【问题标题】:Can I create threads in App Enging using Python?我可以使用 Python 在 App Engine 中创建线程吗?
【发布时间】:2010-04-24 01:52:30
【问题描述】:

此代码能否在 Google App Engine 中创建线程。如果没有,为什么不呢? 类 LogText(db.Model): 内容 = db.StringProperty(multiline=True)

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('')

【问题讨论】:

  • 不确定您使用的是哪个 Python 版本,但这不会与 Python 2.7 和 3.x 并行运行——您会阻止 thr.run(request。相反,您应该使用t.start() 启动一个线程。

标签: python multithreading google-app-engine


【解决方案1】:

App Engine 不允许您创建新线程,这可能是因为 App Engine 的主要目标是构建简单的请求-响应应用程序,而线程通常不被视为“简单”。

App Engine 很难或不可能为应用管理线程以防止滥用(意外或其他原因),因此他们完全禁止它们。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-25
  • 2016-04-06
  • 2015-02-15
相关资源
最近更新 更多