【发布时间】:2024-05-16 18:20:01
【问题描述】:
我有一个在 GAE 中使用 Python 2.5 中的线程运行的应用程序。在上个月我将它更新到 Python 2.7 并且线程已经停止工作。我在 Google 和这里搜索,看看现在 GAE 中的 Python 2.7 线程是否存在问题,但我没有找到任何东西。
代码如下:
def post(self):
bloqueo = thread.allocate_lock()
bloqueo.acquire()
thread.start_new_thread(self.principal,(bloqueo,))
def principal (self,bloqueo):
bloqueo.acquire()
当我运行代码时,它停在 thread.start_new_thread(self.principal,(bloqueo,)) 并给出以下错误:
Thread running after request. Creation traceback:
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/runtime.py", line 151, in HandleRequest
error)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 328, in HandleRequest
return WsgiRequest(environ, handler_name, url, post_data, error).Handle()
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 266, in Handle
result = handler(dict(self._environ), self._StartResponse)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "/base/data/home/apps/s~applcation/8.374533192190096875/src/arc.py", line 1938, in post
thread.start_new_thread(self.principal,(bloqueo,))
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/runtime.py", line 81, in StartNewThread
return base_start_new_thread(Run, ())
你知道是哪一个问题以及如何解决它吗?
谢谢
【问题讨论】:
-
您要导入哪个模块(抱歉之前的回答,我的意思是 GAE 不支持多处理)?
-
您的堆栈跟踪的一部分以及实际错误丢失。
-
嗨 Barack,模块是线程。蒂姆日志中出现的错误是我输入的错误:请求后线程运行。该代码中缺少的独特部分是我们在“主体”中所做的事情,但它永远不会运行这个 def。
-
好的,现在我明白了那里的错误。见下文
标签: python multithreading google-app-engine python-2.7