[ python-Bugs-1242657 ] list(obj) can swallow KeyboardInterrupt
SourceForge.net
noreply at sourceforge.net
Fri Sep 16 11:02:24 CEST 2005
Bugs item #1242657, was opened at 2005-07-22 01:22
Message generated for change (Comment added) made by stevea_zope
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1242657&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Interpreter Core
Group: None
Status: Closed
Resolution: Fixed
Priority: 5
Submitted By: Steve Alexander (stevea_zope)
Assigned to: Raymond Hettinger (rhettinger)
Summary: list(obj) can swallow KeyboardInterrupt
Initial Comment:
The example below shows that list(f) swallows the
KeyboardInterrupt.
It swallows any other exception too, such as
MemoryError or application-specific ConflictErrors.
I think the "get the length of the object" optimisation
should catch only AttributeError and TypeError.
>>> class F(object):
... def __iter__(self):
... yield 23
... def __len__(self):
... print "len called. raising Keyboard
Interrupt."
... raise KeyboardInterrupt
...
>>> f = F()
>>> list(f)
len called. raising Keyboard Interrupt.
[23]
----------------------------------------------------------------------
>Comment By: Steve Alexander (stevea_zope)
Date: 2005-09-16 12:02
Message:
Logged In: YES
user_id=492001
Interestingly, I just saw some code that was causing a
problem in the SchoolTool project. It had a __len__ method
that used list(self), causing great slowness without this
fix, and a RuntimeError "maximum recursion depth exceeded"
with this fix.
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2005-08-21 14:10
Message:
Logged In: YES
user_id=80475
Okay, fixed in several places. This little fragment
occurred in a number of places including code listextend(),
map(), zip(), filter(), and PySequence_Tuple().
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1242657&group_id=5470
More information about the Python-bugs-list
mailing list