Guest User

Untitled

a guest
Jun 25th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. def my_coroutine():
  2. while True:
  3. received = yield
  4. print('Received:', received)
  5. if received == 'Third':
  6. return 3
  7.  
  8.  
  9. def second_coroutine():
  10. a = yield from my_coroutine()
  11. yield a
  12.  
  13. it = my_coroutine()
  14. next(it)
  15. it.send('First')
  16. it.send('Second')
  17. try:
  18. v = it.send('Third')
  19. except StopIteration as e:
  20. print('StopIteration, returned value:', e.value)
  21.  
  22. it2 = second_coroutine()
  23. next(it2)
  24. it2.send('First')
  25. it2.send('Second')
  26. v2 = it2.send('Third')
  27. print('value of yield from:', v2)
  28.  
  29.  
  30. >>>
  31. Received: First
  32. Received: Second
  33. Received: Third
  34. StopIteration, return value: 3
  35. Received: First
  36. Received: Second
  37. Received: Third
  38. value of yield from: 3
Add Comment
Please, Sign In to add comment