[Python-Dev] maximum recursion depth exceeded in lib\pstats.py
Michael Foord
fuzzyman at voidspace.org.uk
Thu Oct 21 14:08:21 CEST 2010
On 21/10/2010 12:20, Adam Bielański wrote:
> Hi all,
>
> There's a bug in Python 2.6, module lib\pstats.py, line 150. I'm
> pretty sure, however that it also exists in other versions, as I don't
> think that profiler differs very much between them.
>
> Let me paste a little piece of surrounding code:
>
> class Stats:
> (....)
> def add(self, *arg_list):
> if not arg_list: return self
> if len(arg_list) > 1: self.add(*arg_list[1:]) #Line 150,
> the problem is right here!
> other = arg_list[0]
> (... do some processing with first item from arg_list ...)
>
> This is the code for adding profiling stats from multiple files (names
> are on arg_list) so that they can be displayed in cumulated and
> readable form.
>
> As you can see it chops off the first item from the list and then uses
> recursion to process the rest of it. It's no wonder then that when you
> profiled a little too many function calls, you're bound to see
> RuntimeError with 'maximum recursion depth exceeded' message when you
> try using this. IMO this should be done with iteration instead, like:
>
> def add(self, *arg_list):
> if not arg_list: return self
> for other in arg_list: #Preserved variable name only for
> sake of comparison with previous snippet
> (... do some processing with each item from arg_list,
> merging results in some rightful manner ...)
>
Without looking at the details your diagnosis and suggested fix seem good.
Please raise an issue on the Python bug tracker - preferably with patch
and test.
http://bugs.python.org/
All the best,
Michael Foord
>
> Kind regards,
> Adam Bielanski.
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> http://mail.python.org/mailman/options/python-dev/fuzzyman%40voidspace.org.uk
--
http://www.voidspace.org.uk/
READ CAREFULLY. By accepting and reading this email you agree,
on behalf of your employer, to release me from all obligations
and waivers arising from any and all NON-NEGOTIATED agreements,
licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap,
confidentiality, non-disclosure, non-compete and acceptable use
policies (”BOGUS AGREEMENTS”) that I have entered into with your
employer, its partners, licensors, agents and assigns, in
perpetuity, without prejudice to my ongoing rights and privileges.
You further represent that you have the authority to release me
from any BOGUS AGREEMENTS on behalf of your employer.
More information about the Python-Dev
mailing list