-
Notifications
You must be signed in to change notification settings - Fork 160
/
print-in-order.py
35 lines (26 loc) · 1.1 KB
/
print-in-order.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import threading
class Foo:
def __init__(self):
self.condition = threading.Condition()
self.stage = 1
def first(self, printFirst: 'Callable[[], None]') -> None:
# printFirst() outputs "first". Do not change or remove this line.
with self.condition:
self.condition.wait_for(lambda: self.stage == 1)
printFirst()
self.stage += 1
self.condition.notify_all()
def second(self, printSecond: 'Callable[[], None]') -> None:
# printSecond() outputs "second". Do not change or remove this line.
with self.condition:
self.condition.wait_for(lambda: self.stage == 2)
printSecond()
self.stage += 1
self.condition.notify_all()
def third(self, printThird: 'Callable[[], None]') -> None:
# printThird() outputs "third". Do not change or remove this line.
with self.condition:
self.condition.wait_for(lambda: self.stage == 3)
printThird()
self.stage += 1
self.condition.notify_all()