fork(3) download
  1. class ImportantThing:
  2. def __enter__(self):
  3. return self
  4. def __exit__(self, *args):
  5. print('Important cleanup')
  6.  
  7. def gen():
  8. with ImportantThing():
  9. try:
  10. yield
  11. except:
  12. print('Neener neener')
  13. yield
  14.  
  15. x = gen()
  16. next(x)
  17. del x
  18. print("Cleanup didn't happen!")
Success #stdin #stdout #stderr 0.02s 28384KB
stdin
Standard input is empty
stdout
Neener neener
Cleanup didn't happen!
stderr
Exception ignored in: <generator object gen at 0x2ac385ad05c8>
RuntimeError: generator ignored GeneratorExit