Title: __call__.__call__ chain cause crash when long enough
Type: crash Stage:
Components: Interpreter Core Versions: Python 2.7
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: alex, amaury.forgeotdarc, christian.heimes, eric.araujo, eric.smith, modchan
Priority: normal Keywords:

Created on 2010-09-02 14:36 by modchan, last changed 2016-09-08 23:32 by christian.heimes. This issue is now closed.

File name Uploaded Description Edit modchan, 2010-09-02 14:36 Example of crashing code
Messages (8)
msg115380 - (view) Author: Lily (modchan) Date: 2010-09-02 14:36
Recursively getting __call__ method from existing __call__ causes interpreter infinitely grow in memory and calling resulting __call__.__call__...__call__.__call__() chain results in crash.

Platform: Windows 7 (x64)
Version: Python 2.7 (r27:82525) win32

Suggested solution:
* let the obj.__call__.__call__ point to obj.__call__
msg115387 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2010-09-02 15:19
I can duplicate this as a segmentation fault under 2.7 on Mac OS, but not under Windows 2.6 (ActiveState).

What platform are you using, and what output do you see?
msg115388 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-09-02 15:27
On Windows, a stack overflow often causes the program to silently exit.
Try to add some print statement at the end and see if it executes.
msg115392 - (view) Author: Alex Gaynor (alex) * (Python committer) Date: 2010-09-02 16:02
This seems to be another case of "C stack depth not reflected in the stack counter".
msg115394 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2010-09-02 16:42
Amaury: Good point. The Windows version is failing, too. A print statement at the end doesn't get executed.
msg116270 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-09-13 01:44
“Recursively getting __call__ method from existing __call__”
I wonder what is the use case for this.
msg116283 - (view) Author: Alex Gaynor (alex) * (Python committer) Date: 2010-09-13 06:46
I doubt there is a good usecase for it, nevertheless we should attempt to fix it, as segfaults are no good.
msg275210 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2016-09-08 23:32
I can no longer reproduce the crash with:

>>> def func(): pass
>>> call = func.__call__
>>> while True:
...     call = call.__call__

Tested with 2.7, 3.5 and 3.6dev.
Date User Action Args
2016-09-08 23:32:29christian.heimessetstatus: open -> closed

nosy: + christian.heimes
messages: + msg275210

resolution: works for me
2010-09-13 06:46:28alexsetmessages: + msg116283
2010-09-13 01:44:53eric.araujosetnosy: + eric.araujo

messages: + msg116270
versions: - Python 2.6
2010-09-02 16:42:01eric.smithsetmessages: + msg115394
2010-09-02 16:02:42alexsetnosy: + alex
messages: + msg115392
2010-09-02 15:27:25amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg115388
2010-09-02 15:19:29eric.smithsetnosy: + eric.smith
messages: + msg115387
2010-09-02 14:36:32modchancreate