import threading
class Foo:
def __init__(self):
self.c = threading.Condition()
self.t = 0
def first(self, printFirst: 'Callable[[], None]') -> None:
# printFirst() outputs "first". Do not change or remove this line.
self.res(0, printFirst)
def second(self, printSecond: 'Callable[[], None]') -> None:
# printSecond() outputs "second". Do not change or remove this line.
self.res(1, printSecond)#里面有没有括号
def third(self, printThird: 'Callable[[], None]') -> None:
# printThird() outputs "third". Do not change or remove this line.
self.res(2, printThird)
def res(self, val: int, func: 'Callable[[], None]') -> None:
with self.c:
self.c.wait_for(lambda: val == self.t)
func()
self.t += 1
self.c.notify_all()
leetcode刷题python之多线程 按序打印
最新推荐文章于 2024-06-09 18:24:57 发布