 <p>Recursion means that each function call stays on the stack, hence you eventually will run out of memory leading to the <code>RecursionError</code>. In other There are ways around this using "tail-call recursion", almost like you've done - <a href="http://stackoverflow.com/a/13592002/764357">except Python will never support this</a>.</p> <p>The best way to run this is to modify your code to have an infinite loop:</p> <pre><code>def get_status(last_media_type, last_state): pass # your method here # except for the recursive call return state, media_type last_state = None last_media_type = 'sensible_default' while True: state, media_type = get_status(last_media_type, last_state) pass # do what you need to compare them here if last_state != state and last_media_type != media_type: print "they aren't equal!" last_state, last_media_type = state, media_type </code></pre> <p>The loop itself (<code>while True:</code>) will consume practically no memory, and now instead of storing every single past state, you just have the last one.</p> <p>Additionally, any information in the method call is garbage collected as it loses scope when your method returns - this is a direct improvement over your code, as in the recursive call nothing <em>ever loses scope</em> so nothing cal ever be collected.</p>