相关疑难解决方法(0)

Stackless Python的缺点是什么?

我最近一直在阅读关于Stackless Python的内容,与vanilla cPython相比,它似乎有很多优点.它具有所有这些很酷的功能,如无限递归,微线程,延续等,同时比cPython更快(大约10%,如果相信Python维基)与之兼容(至少版本2.5,2.6 和3.0).

所有这些看起来好得令人难以置信.但是,TANSTAAFL,我对Python社区中的Stackless没有太大的热情,而PEP 219从未实现过.这是为什么?Stackless的缺点是什么?Stackless'壁橱里藏着什么骷髅?

(我知道Stackless不提供真正的并发性,只是一种更简单的并发编程方式.它并没有真正打扰我.)

python python-stackless

121
推荐指数
3
解决办法
2万
查看次数

Python:超出了最大递归深度

我有以下递归代码,在每个节点我调用sql查询以获取属于父节点的节点.

这是错误:

Exception RuntimeError: 'maximum recursion depth exceeded' in <bound method DictCursor.__del__ of <MySQLdb.cursors.DictCursor object at 0x879768c>> ignored

RuntimeError: maximum recursion depth exceeded while calling a Python object
Exception AttributeError: "'DictCursor' object has no attribute 'connection'" in <bound method DictCursor.__del__ of <MySQLdb.cursors.DictCursor object at 0x879776c>> ignored
Run Code Online (Sandbox Code Playgroud)

我调用以获取sql结果的方法:

def returnCategoryQuery(query, variables={}):
    cursor = db.cursor(cursors.DictCursor);
    catResults = [];
    try:
        cursor.execute(query, variables);
        for categoryRow in cursor.fetchall():
            catResults.append(categoryRow['cl_to']);
        return catResults;
    except Exception, e:
        traceback.print_exc();
Run Code Online (Sandbox Code Playgroud)

我实际上对上述方法没有任何问题,但我还是把它放在了正确的问题概述上.

递归代码:

def leaves(first, path=[]):
    if first:
        for elem in …
Run Code Online (Sandbox Code Playgroud)

python recursion max tree-traversal depth

79
推荐指数
1
解决办法
17万
查看次数