Created
July 9, 2015 21:54
-
-
Save emulbreh/96ce464b7daac3206881 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Worker(object): | |
def __init__(self, tasks): | |
self.enabled = True | |
self.tasks = set(tasks) | |
def is_active(self): | |
return self.enabled and self.tasks | |
def run(self): | |
if self.enabled: | |
task = self.tasks.pop() | |
print(task) | |
class Watcher(object): | |
def __init__(self, worker): | |
self.worker = worker | |
self.was_active = worker.is_active() | |
def watch(self): | |
active = self.worker.is_active() | |
if active != self.was_active: | |
print("worker status changed") | |
self.was_active = active | |
worker = Worker({"1"}) | |
watcher = Watcher(worker) | |
watcher.watch() | |
worker.run() | |
watcher.watch() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment