Skip to content

Instantly share code, notes, and snippets.

@pshchelo
Created July 14, 2020 14:18
Show Gist options
  • Save pshchelo/655d077a1b0e90a4b575999e1e9f91b6 to your computer and use it in GitHub Desktop.
Save pshchelo/655d077a1b0e90a4b575999e1e9f91b6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""Test MySQL tooz driver."""
import os
import platform
import time
from tooz import coordination
url = os.getenv("MYSQL_URL")
host = "mysql-test-%s" % platform.node()
lock_name = "foo"
hold = 60
coord = coordination.get_coordinator(url, host)
coord.start(start_heart=True)
lock = coord.get_lock("lock_name")
print("Attempting to get lock %s for %s" % (lock_name, host))
with lock(blocking=True):
print("Got lock %s for %s, holding for %i sec" % (lock_name, host, hold))
time.sleep(hold)
coord.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment