[Python-Dev] should list's call to len swallow SystemExit? (original) (raw)
Dino Viehland dinov at microsoft.com
Wed Jan 14 05:24:45 CET 2009
- Previous message: [Python-Dev] Python History blog started
- Next message: [Python-Dev] should list's call to __len__ swallow SystemExit?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
We had a bug reported that effectively boils down to we’re not swallowing exceptions when list calls len (http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPython&WorkItemId=20598).
We can obviously make the change to catch exceptions here in IronPython even if it seems like a bad idea to me ☺ But CPython seems to catch not only normal exceptions, but also SystemExit. It seems like there’s been a move away from this so I thought I’d mention it here. I tested it on 2.6.1 and 3.0.
import sys class A(object): def iter(self): return iter(range(10)) def len(self): try: print('exiting') sys.exit(1) except Exception as e: print('can I catch it?', e)
list(A())
which prints:
exiting [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
- Previous message: [Python-Dev] Python History blog started
- Next message: [Python-Dev] should list's call to __len__ swallow SystemExit?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]