fork download
  1. import sys
  2.  
  3. class Foo (object):
  4.  
  5. def __enter__ (self):
  6. print("Enter")
  7. return 1
  8.  
  9. def __exit__ (self, exit, value, exc):
  10. print("Exit")
  11.  
  12. mgr = Foo()
  13. exit = Foo.__exit__
  14. value = Foo.__enter__(mgr)
  15. exc = True
  16. try:
  17. try:
  18. foo = value
  19. print(foo)
  20. except:
  21. exc = False
  22. if not exit(mgr, *sys.exc_info()):
  23. raise
  24. finally:
  25. if exc:
  26. exit(mgr, None, None, None)
Success #stdin #stdout 0.02s 28384KB
stdin
Standard input is empty
stdout
Enter
1
Exit