classification
Title: calling __getattribute__ with wrong instance causes hang up
Type: crash Stage:
Components: Interpreter Core Versions: Python 2.7, Python 2.6
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: Trundle, modchan
Priority: normal Keywords:

Created on 2010-09-02 14:48 by modchan, last changed 2010-09-03 11:32 by benjamin.peterson. This issue is now closed.

Files
File name Uploaded Description Edit
###hanger.py modchan, 2010-09-02 14:48 Example of hanging code
Messages (2)
msg115381 - (view) Author: Lily (modchan) Date: 2010-09-02 14:48
Look for example file.

Current behaviour: one file is started, A.__getattribute__ will be called repeatedly. Entire application will not react on KeyboardInterrupt.

Expected behaviour: exception to be raised "TypeError: unbound method __getattribute__() must be called with A instance as first argument (got M instance instead)"

Platform: Windows 7 (x64)
Version: Python 2.7 (r27: 82525)
msg115433 - (view) Author: Andreas Stührk (Trundle) Date: 2010-09-03 10:22
Actually, Python behaves the way you expect it. The problem is that when that exception is created, Python tries to look up the involved class names. To do that, it tries to get the "__class__" attribute (hapens in `getinstclassname()`, which will call again into A's `__getattibute__`, which will raise again, and for that new exception, "__class__" will be looked up, which will call into `__getattribute__` again, which will raise again and that goes on and on until finally the recursion limit is hit and a recursion error is raised. That recursion error will be discarded by `getinstclassname()`. Hence it's not really a hangup, it just takes a lot of time due to the recursive calls. Try your example with a recursion limit set to a really small value to see the expected behaviour.
History
Date User Action Args
2010-09-03 11:32:33benjamin.petersonsetstatus: open -> closed
resolution: works for me
2010-09-03 10:22:59Trundlesetnosy: + Trundle
messages: + msg115433
2010-09-02 14:50:50modchansetversions: + Python 2.6
2010-09-02 14:48:02modchancreate