This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author dizzy
Recipients dizzy, gregory.p.smith
Date 2010-12-30.00:51:25
SpamBayes Score 6.774358e-05
Marked as misclassified No
Message-id <1293670287.34.0.585233901325.issue10794@psf.upfronthosting.co.za>
In-reply-to
Content
Hi

While working on some Python code I stumbled on a situation where the Python process seems to hang indefinitely. Further debugging points to the following conclusion: if there is a class that somehow manages to run into an infinite recursion (properly detected by Python which raises the corresponding RuntimeError) while Python is doing garbage collection (so the infinite recursion has to be triggered from __del__ somehow) then Python hangs into an infinite loop apparently retrying to call that __del__ indefinitely. The described behavior happens ONLY when an infinite recursion is detected (ie if I raise my own "RuntimeError" from __del__ then it just logs it and exits).

Program showing the problem:

class A(object):
  def __init__(self):
    raise Exception('init error')
    self.m = 'Hello world'

  def __del__(self):
    #raise RuntimeError('my runtime error')
    self.__del__()

def func():
  h = A()

func()

$ python pyloop.py

Traceback (most recent call last):
  File "pyloop.py", line 15, in <module>
    func()
  File "pyloop.py", line 13, in func
    h = A()
  File "pyloop.py", line 5, in __init__
    raise Exception('init error')
Exception: init error
Exception RuntimeError: 'maximum recursion depth exceeded' in <bound method A.__del__ of <__main__.A object at 0x17bb7d0>> ignored
Exception RuntimeError: 'maximum recursion depth exceeded' in <bound method A.__del__ of <__main__.A object at 0x17bb7d0>> ignored
Exception RuntimeError: 'maximum recursion depth exceeded' in <bound method A.__del__ of <__main__.A object at 0x17bb7d0>> ignored
Exception RuntimeError: 'maximum recursion depth exceeded' in <bound method A.__del__ of <__main__.A object at 0x17bb7d0>> ignored
...

If I uncomment the line raising my RuntimeError instance from __del__ then the exception is logged once and the program exits (as expected).

Please help, thanks.
History
Date User Action Args
2010-12-30 00:51:27dizzysetrecipients: + dizzy, gregory.p.smith
2010-12-30 00:51:27dizzysetmessageid: <1293670287.34.0.585233901325.issue10794@psf.upfronthosting.co.za>
2010-12-30 00:51:25dizzylinkissue10794 messages
2010-12-30 00:51:25dizzycreate