Can a simple a==b 'hang' in and endless loop?

Tim Peters tim.peters at gmail.com
Sat Jan 21 05:19:09 CET 2006


[Claudio Grondi]
>> Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit
(Intel)] on win32 - IDLE 1.1.2
>>  >>> a=[]
>>  >>> a.append(a)
>>  >>> b=[]
>>  >>> b.append(b)
>>  >>> a==b
>>
>> Traceback (most recent call last):
>>    File "<pyshell#4>", line 1, in -toplevel-
>>      a==b
>> RuntimeError: maximum recursion depth exceeded in cmp

|[Steven D'Aprano]
> Works for me:

Under a different version of Python, though.

> Python 2.3.3 (#1, May  7 2004, 10:31:40)
> [GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> a = []
> >>> a.append(a)
> >>> b = []
> >>> b.append(b)
> >>> a == b
> True
>
>
> Maybe IDLE is playing silly buggers, or perhaps Python 2.4.2 has a bug.

It's neither.  From the NEWS file for Python 2.4a1:

"""
- Python no longer tries to be smart about recursive comparisons.
  When comparing containers with cyclic references to themselves it
  will now just hit the recursion limit.  See SF patch 825639.
"""



More information about the Python-list mailing list