从modwsgi句柄运行bottle应用程序会导致在调用Python对象时超过最大递归深度



我从我的瓶子应用程序中收到一个奇怪的"RuntimeError:调用Python对象时超过了最大递归深度"。同时从openshiftpaas服务中的wsgi句柄(在virtualenv内)运行它。

回溯并不能让我知道出了什么问题

我还应该提到,直接在我的开发机器上运行bottle脚本(例如pythonapp.py)确实可以正常工作。

edit:为了验证这个问题是否与运行mod_wsgi的bottle有关,我在我的开发计算机上安装了它。运行直python是可行的。使用mod_wsgi运行会给我一个奇怪的运行时间错误编辑结束

我在第201期看到了这个问题已经"解决"了,但可能是针对另一个用例

我在linux服务器中使用python 2.6上的瓶子0.10.9

Critical error while processing request: /about
Error: RuntimeError('maximum recursion depth exceeded while calling a Python object',)
Traceback:
Traceback (most recent call last):
File "path/to/app/virtenv/lib/python2.6/site-packages/bottle-0.10.9-py2.6.egg/bottle.py",
line 824, in wsgi
    out = self._cast(self._handle(environ), request, response)
File "path/to/app/virtenv/lib/python2.6/site-packages/bottle-0.10.9-py2.6.egg/bottle.py",
line 780, in _cast
    return self._cast(out, request, response)

File "path/to/app/virtenv/lib/python2.6/site-packages/bottle-0.10.9-py2.6.egg/bottle.py",
line 780, in _cast
    return self._cast(out, request, response)
File "path/to/app/virtenv/lib/python2.6/site-packages/bottle-0.10.9-py2.6.egg/bottle.py",
line 780, in _cast
    return self._cast(out, request, response)
File "path/to/app/virtenv/lib/python2.6/site-packages/bottle-0.10.9-py2.6.egg/bottle.py",
line 780, in _cast
    return self._cast(out, request, response)
File "path/to/app/virtenv/lib/python2.6/site-packages/bottle-0.10.9-py2.6.egg/bottle.py",
line 780, in _cast
    return self._cast(out, request, response)
File "path/to/app/virtenv/lib/python2.6/site-packages/bottle-0.10.9-py2.6.egg/bottle.py",
line 780, in _cast
    return self._cast(out, request, response)
File "path/to/app/virtenv/lib/python2.6/site-packages/bottle-0.10.9-py2.6.egg/bottle.py",
line 780, in _cast
    return self._cast(out, request, response)
File "path/to/app/virtenv/lib/python2.6/site-packages/bottle-0.10.9-py2.6.egg/bottle.py",
line 780, in _cast
    return self._cast(out, request, response)
File "path/to/app/virtenv/lib/python2.6/site-packages/bottle-0.10.9-py2.6.egg/bottle.py",
line 780, in _cast
    return self._cast(out, request, response)
RuntimeError: maximum recursion depth exceeded while calling a Python object

WSGI句柄:

#!/usr/bin/python
import os
import sys
here = os.path.dirname(os.path.abspath(__file__))

try:
    os.environ['PYTHON_EGG_CACHE'] = os.path.join(os.environ['OPENSHIFT_APP_DIR'],'virtenv/lib/python2.6/site-packages')
except:
    os.environ['PYTHON_EGG_CACHE'] = os.path.join(here,'..','data/virtenv/lib/python2.6/site-packages')
print ('python egg cache set to: %s' % os.environ['PYTHON_EGG_CACHE'])
try:
    virtualenv = os.path.join(os.environ['OPENSHIFT_APP_DIR'],"virtenv/bin/activate_this.py")
except:
    virtualenv = os.path.join(here,'..',"data/virtenv/bin/activate_this.py")
print ('virtualenv is in:%s' % virtualenv)
try:
    execfile(virtualenv, dict(__file__=virtualenv))
    print ('executed')
    sys.path.append(here)
except IOError:
    pass
from myapp import application

myapp.py文件:

#!/bin/usr/env python
#-*- coding:UTF-8 -*-
from bottle import route,run, view, error, static_file, debug, url, redirect, request, response,  default_app
from wikifetch import init_db,load_session,Wikilink, statistic, wiki_populate
import bottle
from sqlalchemy.exc import StatementError
#from config import production_port, production_server
import json
debug(True)
bottle.TEMPLATE_PATH.append("./views")
init_db()
session = load_session()
try:
    stats = statistic()
except:
    print ("no data yet")
    pass
@route('/wsgi')
def show_ip():
    env = request.environ
    for k,v in env.items():
        print k,": ",v
    return env
@route()
def default():
    redirect("/monitor")
@route(["/monitor","/index","/"])
@view("monitor")
def monitor():
    title = request.query.title
    page = request.query.page or 0
    page = int(page)
    try:
        total = stats[0]
        all = session.query(Wikilink).filter(Wikilink.title.like('%'+ title +'%')).count()
        monitor = session.query(Wikilink).order_by('title').filter(Wikilink.title.like('%'+ title +'%')).offset(page*20).limit(20).all() #filter(Wikilink.id>(page*20))
        #print "page=",page," title=",title,
    except StatementError:
        session.rollback()
        #session.begin()
    #print monitor
    return dict(monitor=monitor,pages=(all/20),number=all,total = total)
@route("/why")
@view("why")
def why():
    return dict()
@route("/about")
@view("about")
def about():
    return dict()
@route("/learned")
@view("learned")
def learned():
    return dict()

@route("/stats")
@view("stats")
def statistic():
    return dict(stats= stats)
@route ("/static/<filepath:path>", name="static")
def static(filepath):
    #print 'yey', filepath
    return static_file(filepath,root = "./static/")

@error(404)
def error404(error):
    return static_file('404.html',root="./static")
#@error(502)
@error(500)
def error500(error):
    return static_file('500.html', root = "./static")
application = default_app()
if __name__ =='__main__':
    from wsgiref.simple_server import make_server #using the builtin wsgi server
    httpd = make_server('localhost', 8052, application)

我很乐意提供任何调试线索。

edit:我尝试将递归限制设置得更低,但这只是失败了其他事情(path.append、sqlalchemy等)。当我上升到其他事情失败的水平(准确地说是37)以上时,我会收到这个错误消息。当我跟踪错误日志时,我能够在错误堆栈之前生成另外两行:

[Mon Mar 26 14:50:52 2012] [error] no data yet #if you look in the code above - means that wikiwatch.py file passed the first 'stats' function
[Mon Mar 26 14:50:52 2012] [error] /home/usrname/workspace/appname/data/virtenv/lib/python2.6/site-packages/bottle.py:824: DeprecationWarning: Error handlers must not return :exc:`HTTPResponse`.
[Mon Mar 26 14:50:52 2012] [error]   out = self._cast(self._handle(environ), request, response)

您的代码正在触发错误处理程序,而处理程序似乎正在引发另一个错误。

由于它在没有wsgi处理程序的情况下工作,因此可能是路径问题触发了初始错误。您可以尝试禁用错误处理程序以查看瓶子错误页面,这可能会对问题有所了解。

在处理程序中引发的错误时,我注意到在static()函数中,您使用了关键字参数root="./static/",而在错误处理程序中,您省略了尾部斜杠。

最新更新