Google App Engine任务队列 - 令人讨厌的失败

时间:2011-02-06 17:08:21

标签: python google-app-engine task-queue

我正在为GAE开发一个应用程序,并尝试使用任务队列。目前,我只是通过GAE App Launcher在我的Windows机器上运行这个东西,但每当我尝试排队任何东西时,开发'服务器'崩溃并且日志充满讨厌的输出。

taskqueue.add(url='/processWork', params={'key', myModel.key()})

我已尝试在与其他工作的交易中运行此操作,因此我非常确定该工作已成功排队。

然而,不久之后,开发服务器崩溃,日志中充满了这样的东西:

ERROR    2011-02-06 17:04:23,289
__init__.py:395] global name 'true' is not defined Traceback (most recent call last):   File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 517, in __call__
    handler.post(*groups)   File "C:\Projects\GAE\MyApp\main.py", line 114, in post
    activity.approved = true NameError: global name 'true' is not defined INFO     2011-02-06 17:04:23,309 dev_appserver.py:3317] "POST /processWork HTTP/1.1" 500 - WARNING  2011-02-06 17:04:23,309 taskqueue_stub.py:586] Task named "task1" on queue "default" failed with code 500; will retry in 30 seconds Traceback (most recent call last):   File "C:\Python27\lib\SocketServer.py", line 284, in _handle_request_noblock
    self.process_request(request, client_address)   File "C:\Python27\lib\SocketServer.py", line 311, in process_request
    self.shutdown_request(request)   File "C:\Python27\lib\SocketServer.py", line 459, in shutdown_request
    request.shutdown(socket.SHUT_WR) AttributeError: 'FakeConnection' object has no attribute 'shutdown' ERROR    2011-02-06 17:04:23,312 dev_appserver_main.py:494] Error encountered: Traceback (most recent call last):
    File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver_main.py", line 488, in main
    http_server.serve_forever()
    File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3947, in serve_forever
    self.handle_request()
    File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3913, in handle_request
    self._handle_request_noblock()
    File "C:\Python27\lib\SocketServer.py", line 287, in _handle_request_noblock
    self.shutdown_request(request)
    File "C:\Python27\lib\SocketServer.py", line 459, in shutdown_request
    request.shutdown(socket.SHUT_WR)   AttributeError: 'FakeConnection' object has no attribute 'shutdown'   Now terminating.
---------------------------------------- Exception happened during processing of request from ('0.1.0.2', 80)
---------------------------------------- 2011-02-06 09:04:23 (Process exited with code 1)

道歉 - 下面的回复发现了错字(真实,不是真)。然而,这在尝试解决原始问题时悄然而至。如果我修复了拼写错误,排队的工作就完成了,但我的服务器仍然在日志中出现此错误:

INFO     2011-02-06 17:50:32,882 dev_appserver.py:3317] "POST /processWork HTTP/1.1" 200 -
Traceback (most recent call last):
  File "C:\Python27\lib\SocketServer.py", line 284, in _handle_request_noblock
    self.process_request(request, client_address)
  File "C:\Python27\lib\SocketServer.py", line 311, in process_request
    self.shutdown_request(request)
  File "C:\Python27\lib\SocketServer.py", line 459, in shutdown_request
    request.shutdown(socket.SHUT_WR)
AttributeError: 'FakeConnection' object has no attribute 'shutdown'
ERROR    2011-02-06 17:50:32,884 dev_appserver_main.py:494] Error encountered:
Traceback (most recent call last):

  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver_main.py", line 488, in main
    http_server.serve_forever()

  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3947, in serve_forever
    self.handle_request()

  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3913, in handle_request
    self._handle_request_noblock()

  File "C:\Python27\lib\SocketServer.py", line 287, in _handle_request_noblock
    self.shutdown_request(request)

  File "C:\Python27\lib\SocketServer.py", line 459, in shutdown_request
    request.shutdown(socket.SHUT_WR)

AttributeError: 'FakeConnection' object has no attribute 'shutdown'

Now terminating.
----------------------------------------
Exception happened during processing of request from ('0.1.0.2', 80)
----------------------------------------
2011-02-06 09:50:32 (Process exited with code 1)

如果我删除对taskqueue.add的调用,它工作正常(当然没有排队的工作)。出了什么问题?

5 个答案:

答案 0 :(得分:8)

File "C:\Python27\lib\SocketServer.py"

App Engine使用Python 2.5运行,您使用的是Python 2.7。

答案 1 :(得分:5)

看起来像一个简单的拼写错误:

__init__.py:395] global name 'true' is not defined 
Traceback (most recent call last):   
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 517, in __call__
    handler.post(*groups)   
File "C:\Projects\GAE\MyApp\main.py", line 114, in post
    activity.approved = true NameError: global name 'true' is not defined

转到main.py第395行并更改

 activity.approved = true

 activity.approved = True

(大写“T”)

答案 2 :(得分:0)

是的,这是因为你使用的是2.7。 2.6中添加了shutdown()。你必须运行2.5

答案 3 :(得分:0)

你可以实际修补补丁(从Python 2.7.1开始,pyOpenSSL 0.12和Werkzeug 0.6.2):

### WARNING: Monkey patch in a fix to correct pyOpenSSL's
### incompatible ServerSocket implementation that accepts zero arguments
### for shutdown() instead of one. Fix is for:
### lib/python2.7/SocketServer.py:459's shutdown() call because that
### appears to be easier to quickly hack in versus patching
### pyOpenSSL. Again, don't use this for production, but it's great for
### testing.
def monkeyp_ssl_shutdown_request(self, request):
    try:
        request.shutdown()
    except socket.error:
        pass #some platforms may raise ENOTCONN here
    self.close_request(request)
from SocketServer import TCPServer
TCPServer.shutdown_request = monkeyp_ssl_shutdown_request

不漂亮,但是当有人关闭SSL TCP连接时,它比异常更好。

app.run(ssl_context='adhoc') # Now works

答案 4 :(得分:0)

另一个可能的原因是您无法导入模块

from google.appengine.api import taskqueue