Skip to content

Instantly share code, notes, and snippets.

@harlowja
Created October 24, 2017 22:27
Show Gist options
  • Save harlowja/7abc0d60296fd881bb4817bb0a72289b to your computer and use it in GitHub Desktop.
Save harlowja/7abc0d60296fd881bb4817bb0a72289b to your computer and use it in GitHub Desktop.
import contextlib
import os
import socket
import time
from kazoo import client
def do_hello():
print("Hello from %s:%s" % (socket.gethostname(), os.getpid()))
while True:
time.sleep(5)
def main():
k_client = client.KazooClient(hosts=os.environ['ZOOKEEPER_HOSTS'])
k_client.start()
with contextlib.closing(k_client):
e = k_client.Election("/hello")
e.run(do_hello)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment