fork(11) download
  1. def gen(text):
  2. try:
  3. for line in text:
  4. try:
  5. yield int(line)
  6. except:
  7. # Ignore blank lines - but catch too much!
  8. pass
  9. finally:
  10. print('Doing important cleanup')
  11.  
  12. text = ['1', '', '2', '', '3']
  13.  
  14. if any(n > 1 for n in gen(text)):
  15. print('Found a number')
  16.  
  17. print('Oops, no cleanup.')
Success #stdin #stdout #stderr 0.04s 9528KB
stdin
Standard input is empty
stdout
Found a number
Oops, no cleanup.
stderr
Exception ignored in: <generator object gen at 0x2b749b1db5c8>
RuntimeError: generator ignored GeneratorExit