class Foo:
called = set()
def first(self, printFirst: 'Callable[[], None]') -> None:
# printFirst() outputs "first". Do not change or remove this line.
printFirst()
self.called.add(1)
def second(self, printSecond: 'Callable[[], None]') -> None:
# printSecond() outputs "second". Do not change or remove this line.
while 1 not in self.called:
time.sleep(10**-10)
else:
printSecond()
self.called.add(2)
def third(self, printThird: 'Callable[[], None]') -> None:
# printThird() outputs "third". Do not change or remove this line.
while 2 not in self.called:
time.sleep(10**-10)
else:
printThird() ? понятно, что по уму threading.lock() и вперед, но тем не менее...
class Foo: class Event: def __init__(self): self._is_set = False def ready(self): return self._is_set def notify(self): self._is_set = True def __init__(self): self.first_executed = self.Event() self.second_executed = self.Event() def first(self, printFirst: 'Callable[[], None]') -> None: # printFirst() outputs "first". Do not change or remove this line. printFirst() self.first_executed.notify() def second(self, printSecond: 'Callable[[], None]') -> None: # printSecond() outputs "second". Do not change or remove this line. while not self.first_executed.ready(): pass printSecond() self.second_executed.notify() def third(self, printThird: 'Callable[[], None]') -> None: # printThird() outputs "third". Do not change or remove this line. while not self.second_executed.ready(): pass printThird() такая штука прошла у меня, по факту твой же сет но лучше все же использовать реальные локи или ивенты
засунул в инит, приняли.
Обсуждают сегодня