-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoordinator.py
More file actions
40 lines (28 loc) · 1.04 KB
/
Copy pathcoordinator.py
File metadata and controls
40 lines (28 loc) · 1.04 KB
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
from threading import Thread
import time
from services import api_service
from services import telegram_service
import config
class Coordinator:
def __init__(self):
self.api_service = api_service.ApiService(config.api_service)
self.telegram_service = telegram_service.TelegramService(config.telegram)
pass
def run(self):
self.get_threads = []
self.get_threads.append(lambda: Thread(target=lambda: self.api_service.run()))
self.get_threads.append(lambda: Thread(target=lambda: self.telegram_service.run()))
self.threads = [get_thread() for get_thread in self.get_threads]
while True:
self._thread_start()
time.sleep(30)
return
def _thread_start(self):
for it, thread in enumerate(self.threads):
if not thread.is_alive():
try:
thread.start()
except:
self.threads[it] = self.get_threads[it]()
self.threads[it].start()
return