-
Notifications
You must be signed in to change notification settings - Fork 0
/
ibotmanager.py
46 lines (31 loc) · 1.05 KB
/
ibotmanager.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
# -*- coding:utf-8 -*-
import os
import time
import signal
import atexit
import logging
from threading import Thread
import config
from bot.instabot import InstaBot, RUN
from utils import get_all_modules, get_config_from_module, Logger
if not os.path.exists(config.LOG_TO):
os.makedirs(config.LOG_TO)
fh = logging.FileHandler(os.path.join(config.LOG_TO, config.LOGGER.get('file')))
fh.setLevel(config.LOGGER.get('level'))
fh.setFormatter(config.LOGGER.get('formatter'))
log = Logger("IBotManager", fh)
modules = get_all_modules()
threads = [Thread(target=InstaBot(**get_config_from_module(module_name[:-3])).new_auto_mod,
name=module_name[:-3]) for module_name in modules]
for t in threads:
try:
log.debug("Try start '%s' bot" % t.name)
t.start()
log.debug("Successfully start '%s' bot." % t.name)
except Exception as ex:
log.exception("Error during work bot")
[t.join() for t in threads if t.is_alive()]
def stop_all_process():
signal.alarm(1)
atexit.register(stop_all_process)
time.sleep(5)