Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from contextlib import contextmanager
- from uuid import uuid4
- class MultiStopIteration(StopIteration):
- def __init__(self, uuid):
- self.uuid = uuid
- def throw(self):
- raise self
- @contextmanager
- def multibreak():
- uuid = uuid4()
- try:
- yield MultiStopIteration(uuid).throw
- except MultiStopIteration as e:
- if e.uuid != uuid:
- raise
- with multibreak() as stop1:
- for x in range(1, 4):
- for y in range(1, 4):
- with multibreak() as stop2:
- for z in range(1, 4):
- print(x, y, z)
- stop1()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement