[Python-Dev] maximum recursion depth exceeded in lib\pstats.py (original) (raw)

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, *arglist): if not arglist: return self if len(arglist) > 1: self.add(*arglist[1:]) #Line 150, the problem is right here! other = arglist[0] (... do some processing with first item from arglist ...) This is the code for adding profiling stats from multiple files (names are on arglist) 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, *arglist): if not arglist: return self for other in arglist: #Preserved variable name only for sake of comparison with previous snippet (... do some processing with each item from arglist, 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