2012-03-22 14 views
0

我从瓶子应用程序中收到一个奇怪的“RuntimeError:调用Python对象时超出最大递归深度”。同时从wsgi句柄(在virtualenv中)运行它在openshift paas服务。从mod_wsgi句柄运行瓶子应用程序导致在调用Python对象时超出最大递归深度

回溯没有提供我一个不好的事

我应该还提到,在我的开发MACHING(如蟒蛇pythonapp.py)运行脚本瓶直不正常工作的线索。

编辑:为了验证这个问题是连接到与mod_wsgi运行瓶我安装它在我的开发计算机。运行直蟒作品。与mod_wsgi的运行让我编辑的这个陌生的RuntimeError

我的问题#201 看到,这个问题已经“解决”,但可能用于其他用途的情况下

我用一瓶0.10.9上蟒蛇2.6 Linux服务器

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) 

我会很高兴为任何调试线索。

编辑:我尝试设置递归限制较低,但只是失败其他的事情(path.append,SQLAlchemy的等等),我起来,其他的事情失败的水平以上(37准确地说)然后我得到此错误消息。当我被盯梢的错误日志,我能够生产另外2行错误堆栈之前去:

[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) 
+1

设置递归限制要低得多,以便我们可以看到是什么调用。 – 2012-03-26 01:11:12

+0

@ IgnacioVazquez-Abrams试过,似乎不是非常有用,但把它作为编辑。 – alonisser 2012-03-26 22:05:59

回答

1

您的代码触发了错误处理程序,它似乎是在处理程序提出另一项错误。

因为它没有使用wsgi处理函数,所以它可能是一个触发初始错误的路径问题。您可以尝试关闭错误处理程序以查看瓶子错误页面,这可能会对此问题有所了解。

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

+0

我禁用了错误处理程序,但给了相同的错误页面..我不认为错误处理程序是问题。你能否就我应该检查哪种路径错误提出建议? – alonisser 2012-03-27 19:03:12

+0

@alonisser只是sys.path的内容,是您导入可访问的模块。你的wsgi处理程序用'sys.path.append(here)'设置路径,并且通过调用virtualenv激活脚本。你可以尝试直接像运行pythonapp.py脚本一样运行wsgi处理程序。只需将相同的'if __name__ =='__main __':'块添加到wsgi.py(或任何名称)的末尾并运行'python wsgi.py'。这应该与直接运行脚本相同,但是使用由wsgi处理程序设置的路径。 – 2012-03-28 07:27:24

相关问题