gpt4 book ai didi

python - GAE Python 开发服务器在升级到 2.7 后间歇性崩溃

转载 作者:太空狗 更新时间:2023-10-30 01:35:07 24 4
gpt4 key购买 nike

我最近将我的 GAE Python 应用程序升级到了 Python 2.7。从那时起,我定期在开发服务器上收到以下错误,并且开发服务器提供空白页面:

Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 168, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 206, in _LoadHandler
handler = __import__(path[0])
[...]
File "/Users/joneill/OpenSTV/OpenSTV/trunk/OpaVote-HR/main.py", line 2, in <module>
import views
[...]
File "/Users/joneill/OpenSTV/OpenSTV/trunk/OpaVote-HR/views.py", line 3, in <module>
from pytz.gae import pytz
[...]
File "/Users/joneill/OpenSTV/OpenSTV/trunk/OpaVote-HR/pytz/__init__.py", line 34, in <module>
from pkg_resources import resource_stream
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 662, in Decorate
return func(self, *args, **kwargs)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1818, in load_module
return self.FindAndLoadModule(submodule, fullname, search_path)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 662, in Decorate
return func(self, *args, **kwargs)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1690, in FindAndLoadModule
description)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 662, in Decorate
return func(self, *args, **kwargs)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1615, in LoadModuleRestricted
return source_file.load_module(submodule_fullname)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/dist/py_zipimport.py", line 246, in load_module
submodname, is_package, fullpath, source = self._get_source(fullmodname)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/dist/py_zipimport.py", line 207, in _get_source
source = self.zipfile.read(relpath.replace(os.sep, '/'))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/zipfile.py", line 867, in read
return self.open(name, "r", pwd).read()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/zipfile.py", line 882, in open
zef_file = open(self.filename, 'rb')
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 578, in __init__
raise IOError(errno.EACCES, 'file not accessible', filename)
IOError: [Errno 13] file not accessible: '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg'
INFO 2012-01-21 20:50:44,222 dev_appserver.py:2832] "POST /manage HTTP/1.1" 500 -

一些注意事项:

  • 这不会发生在生产服务器上。
  • 在开发服务器上,我的应用程序将运行几分钟,然后发生此错误。
  • 如果我在开发服务器上停止并重新启动我的应用程序,它会再次运行几分钟。
  • 我正在使用最新版本的 gae-pytz你可以看到它在那里导入失败。
  • 我删除的 [...] 与您在最后看到的内容相似。
  • 我不知道为什么最后会调用 setuptools。
  • 我正在使用装有 Lion 的 Mac。

我可以使用开发服务器,但每隔几分钟就停止并重新启动真的很烦人。有什么解决办法吗?

最佳答案

堆栈跟踪中的实际问题是您的代码正在尝试从站点包中导入设置工具,而开发服务器不会执行此操作。

'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg'

您需要在您的应用程序代码库中包含设置工具。它有时有效的事实表明您通过各种模块的代码路径不同,并且可能(取决于您在开发中的测试)不同的导入顺序意味着设置工具已导入其他地方,或者仅在代码中的某些点需要.

查看导入 pytz 的堆栈跟踪的第 4 行,下一行是 from pkg_resources import resource_stream 那是触发其余导入问题的原因。我在项目的根目录下使用了一个假的截断 pkg_resources,它最终不会尝试从设置工具中导入内容。您可以在调试导入模式下运行开发服务器,这会告诉您更多信息

这是一个假的 pkg_resources。

"""Package resource API
--------------------

A resource is a logical file contained within a package, or a logical
subdirectory thereof. The package resource API expects resource names
to have their path parts separated with ``/``, *not* whatever the local
path separator is. Do not use os.path operations to manipulate resource
names being passed into the API.

The package resource API is designed to work with normal filesystem packages,
.egg files, and unpacked .egg files. It can also work in a limited way with
.zip files and with custom PEP 302 loaders that support the ``get_data()``
method.
"""

import sys, os, zipimport, time, re, imp, new

try:
frozenset
except NameError:
from sets import ImmutableSet as frozenset

from os import utime #, rename, unlink # capture these to bypass sandboxing
from os import open as os_open

可能有其他/更好的方法来做到这一点,但它对我有用。

哦,我还建议你使用 http://code.google.com/p/gae-pytz/而不是 pytz。

干杯

关于python - GAE Python 开发服务器在升级到 2.7 后间歇性崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8956712/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com