deforum / deforum/deforum-stable-diffusion

RecursionError: maximum recursion depth exceeded while calling a Python object.

Open
#169 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
2.3k
Forks
412
PR merge metrics
No merged PRs in 30d

Description

### Discussed in https://github.com/deforum-art/deforum-stable-diffusion/discussions/168

Originally posted by **dhmiller** March 31, 2023
I did a Google search for this error and got the answer below but couldn't really interpret it. Is it something the devs could modify in Deforum,? Trying to do long renders (6, 7k keyframes) but they fail half way through (except when they don't - i.e., sometimes I can do a 9k keyframe render with no problem) ... Here's what I found:

Python don't have a great support for recursion because of it's lack of TRE (Tail Recursion Elimination).

This means that each call to your recursive function will create a function call stack and because there is a limit of stack depth (by default is 1000) that you can check out by sys.getrecursionlimit (of course you can change it using sys.setrecursionlimit but it's not recommended) your program will end up by crashing when it hits this limit.

As other answer has already give you a much nicer way for how to solve this in your case (which is to replace recursion by simple loop) there is another solution if you still want to use recursion which is to use one of the many recipes of implementing TRE in python like this one.

N.B: My answer is meant to give you more insight on why you get the error, and I'm not advising you to use the TRE as i already explained because in your case a loop will be much better and easy to read.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the long-render scenario described in issue #169 and review discussion #168, especially the failure around 6–7k keyframes. Capture the full traceback and identify the Deforum entry point where recursion exceeds the limit. Done means the cause is isolated and long renders complete reliably without relying on an arbitrary recursion-limit increase.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.