-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
51 lines (39 loc) · 1.06 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from node import Node, AppendEntriesRequest, Log
import threading
def request(command, _from):
node: Node = Node.NODES[_from - 1]
node.broadcast_append_entries_request(
AppendEntriesRequest(
node_id=_from,
leader_id=node.current_leader.node_id,
current_term=node.current_term,
prefix_len=0,
prefix_term=0,
commit_len=0,
suffix=[
Log(
term=node.current_term,
command=command
)
]
)
)
def stop():
Node.STOP_LEADER.set()
def start():
Node.STOP_LEADER.clear()
def main():
node1 = Node()
node2 = Node()
node3 = Node()
threads = [
threading.Thread(target=node1.start, daemon=True),
threading.Thread(target=node2.start, daemon=True),
threading.Thread(target=node3.start, daemon=True),
]
for thread in threads:
thread.start()
# for thread in threads:
# thread.join()
if __name__ == "__main__":
main()