Note that there are some explanatory texts on larger screens.

plurals
  1. POPython: Maximum recursion depth exceeded
    text
    copied!<p>I have the following recursion code, at each node I call sql query to get the nodes belong to the parent node. </p> <p>here is the error: </p> <pre><code>Exception RuntimeError: 'maximum recursion depth exceeded' in &lt;bound method DictCursor.__del__ of &lt;MySQLdb.cursors.DictCursor object at 0x879768c&gt;&gt; ignored RuntimeError: maximum recursion depth exceeded while calling a Python object Exception AttributeError: "'DictCursor' object has no attribute 'connection'" in &lt;bound method DictCursor.__del__ of &lt;MySQLdb.cursors.DictCursor object at 0x879776c&gt;&gt; ignored </code></pre> <p>Method that I call to get sql results:</p> <pre><code>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(); </code></pre> <p>I actually don't have any issue with the above method but I put it anyways to give proper overview of the question.</p> <p>Recursion Code:</p> <pre><code>def leaves(first, path=[]): if first: for elem in first: if elem.lower() != 'someString'.lower(): if elem not in path: queryVariable = {'title': elem} for sublist in leaves(returnCategoryQuery(categoryQuery, variables=queryVariable)): path.append(sublist) yield sublist yield elem </code></pre> <p>Calling the recursive function </p> <pre><code>for key, value in idTitleDictionary.iteritems(): for startCategory in value[0]: print startCategory + " ==== Start Category"; categoryResults = []; try: categoryRow = ""; baseCategoryTree[startCategory] = []; #print categoryQuery % {'title': startCategory}; cursor.execute(categoryQuery, {'title': startCategory}); done = False; while not done: categoryRow = cursor.fetchone(); if not categoryRow: done = True; continue; rowValue = categoryRow['cl_to']; categoryResults.append(rowValue); except Exception, e: traceback.print_exc(); try: print "Printing depth " + str(depth); baseCategoryTree[startCategory].append(leaves(categoryResults)) except Exception, e: traceback.print_exc(); </code></pre> <p>Code to print the dictionary, </p> <pre><code>print "---Printing-------" for key, value in baseCategoryTree.iteritems(): print key, for elem in value[0]: print elem + ','; raw_input("Press Enter to continue...") print </code></pre> <p>If the recursion is too deep I should be getting the error when I call my recursion function, but when I get this error when I print the dictionary.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload