classification
Title: dir() hangs interpreter
Type: crash Stage:
Components: Versions: Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: sfaleron, steven.daprano
Priority: normal Keywords:

Created on 2018-08-06 13:57 by sfaleron, last changed 2018-08-06 19:54 by sfaleron.

Files
File name Uploaded Description Edit
splat.py sfaleron, 2018-08-06 19:53
Messages (3)
msg323208 - (view) Author: Chris Fuller (sfaleron) Date: 2018-08-06 13:57
It's a little obscure. Nothing to get alarmed about, probably. It involves recursion and __getattr__() during object creation.

Only present with 2.7 new-style classes. Old-style 2.7 did not exhibit this behavior nor did 3.x. Checked on Linux/Cygwin/Windows.
msg323212 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2018-08-06 15:13
I don't think the description you give is very accurate. The description in the file splat.py says:

"Hangs/core dumps Python2 when instantiated"

(which is it? hang or core dump?)

but I can't replicate that. Instantiating A() is fine for me. (Tested in Python 2.7 on Linux.)

The whole business about "splat" is amusing but irrelevant. I can replicate the hang (no core dump) using this simpler example:

class B:
    def __getattr__(self, name):
        return name in dir(self)


Instantiating the class is fine, but calling dir() on it locks up:

>>> b = B()
>>> dir(b)

[1]+  Stopped                 python2.7 -E

(after typing Ctrl-Z in the xterm). Notice that B is an old-style class in this example. The same behaviour also occurs when inheriting from object.
msg323218 - (view) Author: Chris Fuller (sfaleron) Date: 2018-08-06 19:54
It hangs, and on Cygwin it dumped core when I hit ctrl-break. I uploaded a revised script. It';s a heisenbug, all I did was removed the unused splat method.
History
Date User Action Args
2018-08-06 19:54:59sfaleronsetmessages: + msg323218
2018-08-06 19:53:10sfaleronsetfiles: + splat.py
2018-08-06 19:52:45sfaleronsetfiles: - splat.py
2018-08-06 15:13:23steven.dapranosetnosy: + steven.daprano
messages: + msg323212
2018-08-06 13:57:49sfaleroncreate