Skip to content

Instantly share code, notes, and snippets.

@emulbreh
Created July 9, 2015 21:54
Show Gist options
  • Save emulbreh/96ce464b7daac3206881 to your computer and use it in GitHub Desktop.
Save emulbreh/96ce464b7daac3206881 to your computer and use it in GitHub Desktop.
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