fork download
  1. import contextlib
  2. import threading
  3. import time
  4.  
  5. @contextlib.contextmanager
  6. def cm():
  7. try:
  8. yield
  9. finally:
  10. print 'in __exit__'
  11.  
  12. def f():
  13. with cm():
  14. print 'in with block'
  15. event.set()
  16. time.sleep(10)
  17.  
  18. event = threading.Event()
  19.  
  20. t = threading.Thread(target=f)
  21. t.daemon = True
  22. t.start()
  23.  
  24. event.wait()
Success #stdin #stdout 0s 91264KB
stdin
Standard input is empty
stdout
in with block