-
Notifications
You must be signed in to change notification settings - Fork 0
/
dht_indexer.py
36 lines (27 loc) · 1.03 KB
/
dht_indexer.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
from threading import Thread
from multiprocessing import Process
from dht_indexer_config import *
from service.indexer import start_indexer
def watchdog_thread(**kwargs):
while True:
p = Process(target=start_indexer, kwargs=kwargs)
p.start() # Startup new process
p.join()
def start_indexers(web_server_api_url, indexers_info):
threads = []
for indexer_info in indexers_info:
kwargs = {
"web_server_api_url": web_server_api_url,
"port": indexer_info["port"],
"node_id": indexer_info["node_id"],
"bootstrap_node_address": indexer_info["bootstrap"],
"time_to_live": 20 * 60 # Stop process after 20 minutes
}
t = Thread(target=watchdog_thread, kwargs=kwargs)
t.start()
threads.append(t)
# Wait until all processes end
map(lambda thread: thread.join(), threads)
if __name__ == '__main__':
start_indexers(web_server_api_url=WEB_SERVER_API_URL,
indexers_info=DHT_INDEXERS_INFO)