-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_process_replication.py
72 lines (59 loc) · 2.33 KB
/
test_process_replication.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Script to show an usage example
The idea is to have 4 process that duplicate the same data. Each process have his own local date.
When a process edit his local he do the folling step:
1. Ask the permition af all other process to edit
2. When is get all ok from other proces he send the new data, value to other process
3. Wait the reception of each messages
4. Edit his local value
Each data have a value
"""
from __future__ import absolute_import
from event_bus import ProcessManager
from process_replication import ProcessReplication
import logging.handlers
import os
PYTHON_LOGGER = logging.getLogger(__name__)
if not os.path.exists("log"):
os.mkdir("log")
HDLR = logging.handlers.TimedRotatingFileHandler("log/exam_2018_2019.log",
when="midnight", backupCount=60)
STREAM_HDLR = logging.StreamHandler()
FORMATTER = logging.Formatter("%(asctime)s %(filename)s [%(levelname)s] %(message)s")
HDLR.setFormatter(FORMATTER)
STREAM_HDLR.setFormatter(FORMATTER)
PYTHON_LOGGER.addHandler(HDLR)
PYTHON_LOGGER.addHandler(STREAM_HDLR)
PYTHON_LOGGER.setLevel(logging.DEBUG)
# Absolute path to the folder location of this python file
FOLDER_ABSOLUTE_PATH = os.path.normpath(os.path.dirname(os.path.abspath(__file__)))
my_local_storage = {}
process_launch = ProcessManager()
process_launch.add_process(4, ProcessReplication)
print("commend the you can do. To exit enter `exit`")
print("set id (0, n-1), data, value")
print("edit id (0, n-1), data, value")
process_launch.process_list[0].set("a", "120")
process_launch.process_list[1].set("a", "120")
process_launch.process_list[2].set("a", "120")
process_launch.process_list[2].set("b", "100")
process_launch.process_list[3].set("b", "100")
while True:
txt = input(">>>")
if txt == "exit":
break
elif "edit" in txt:
pro_id, data, value = txt.replace('edit', '').split(',')
data = data.strip()
value = value.strip()
pro_id = int(pro_id.strip())
process_launch.process_list[pro_id].edit(data, value)
elif "set" in txt:
pro_id, data, value = txt.replace('set', '').split(',')
data = data.strip()
value = value.strip()
pro_id = int(pro_id.strip())
process_launch.process_list[pro_id].set(data, value)
process_launch.stop_process()