Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. from contextlib import contextmanager
  2. from uuid import uuid4
  3.  
  4. class MultiStopIteration(StopIteration):
  5.     def __init__(self, uuid):
  6.         self.uuid = uuid
  7.     def throw(self):
  8.         raise self
  9.  
  10. @contextmanager
  11. def multibreak():
  12.     uuid = uuid4()
  13.     try:
  14.         yield MultiStopIteration(uuid).throw
  15.     except MultiStopIteration as e:
  16.         if e.uuid != uuid:
  17.             raise
  18.  
  19. with multibreak() as stop1:
  20.     for x in range(1, 4):
  21.         for y in range(1, 4):
  22.             with multibreak() as stop2:
  23.                 for z in range(1, 4):
  24.                     print(x, y, z)
  25.                     stop1()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement