Skip to content

Commit

Permalink
Picking lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
mlinvill committed Jul 17, 2023
1 parent 44e6812 commit fa73897
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
5 changes: 4 additions & 1 deletion distributed/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
#
"""
distributedlock
""""
20 changes: 10 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import multiprocessing as mp
from multiprocessing import Value
from rich.console import Console
from distributed.lock import DistributedLock, statedesc
from .distributed.lock import DistributedLock, statedesc


def runlock(mynode: str, peerlist: List, leader_state: Value):
Expand All @@ -32,7 +32,7 @@ def runlock(mynode: str, peerlist: List, leader_state: Value):

if __name__ == "__main__":
mp.set_start_method("spawn")
me = False
myhosturi = False
peers = []

console = Console()
Expand All @@ -43,7 +43,7 @@ def runlock(mynode: str, peerlist: List, leader_state: Value):
args = json.loads(sys.argv)

if ("me" or "hosturi") in args.lower():
me = args["me"]
myhosturi = args["me"]
if "peerA" in args.lower():
peers.append(args["peerA"])
if "peerB" in args.lower():
Expand All @@ -53,37 +53,37 @@ def runlock(mynode: str, peerlist: List, leader_state: Value):
else:

if "HOSTURI" in os.environ:
me = os.environ["HOSTURI"]
myhosturi = os.environ["HOSTURI"]
if "PEERA_URI" in os.environ:
peers.append(os.environ["PEERA_URI"])
if "PEERB_URI" in os.environ:
peers.append(os.environ["PEERB_URI"])
if "PEERC_URI" in os.environ:
peers.append(os.environ["PEERC_URI"])

assert me is not False
assert myhosturi is not False
assert len(peers) != 0

console.log(f"I am {me}")
console.log(f"I am {myhosturi}")
console.log(f"peers are {peers}")

LASTSTATE = None
leader = mp.Value("i", 0, lock=True)

p = mp.Process(target=runlock, args=(me, peers, leader))
p = mp.Process(target=runlock, args=(myhosturi, peers, leader))
p.start()

try:
while True:
status = leader.value
if LASTSTATE != status:
console.log(f"me: {me}\tstate: {statedesc[status]}")
console.log(f"me: {myhosturi}\tstate: {statedesc[status]}")
LASTSTATE = status

sleep(2)

except Exception as e:
print(f"Encountered exception! {e}")
except Exception as error:
print(f"Encountered exception! {error}")

finally:
p.join()

0 comments on commit fa73897

Please sign in to comment.