-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_bots.py
executable file
·61 lines (42 loc) · 1.34 KB
/
start_bots.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
#!/usr/bin/env python3
import signal
import threading
import time
from QQuizGame.Author import Author
from QQuizGame.Game import Game
class BotThread(threading.Thread):
def __init__(self, bot):
threading.Thread.__init__(self)
self.shutdown_flag = threading.Event()
self.bot = bot
def run(self):
print(self.bot.__name__ + ' started')
while not self.shutdown_flag.is_set():
self.bot.start_polling(True)
self.bot.stop_polling()
print(self.bot.__name__ + ' stopped')
class ServiceExit(Exception):
pass
def service_shutdown(signum, frame):
print('Caught signal %d' % signum)
raise ServiceExit
def main():
signal.signal(signal.SIGTERM, service_shutdown)
signal.signal(signal.SIGINT, service_shutdown)
try:
game = Game("./configs/qgame_config.yaml")
game_tread = BotThread(game)
auth = Author("./configs/qauthor_config.yaml")
auth_tread = BotThread(auth)
game_tread.start()
auth_tread.start()
while True: time.sleep(0.5)
except ServiceExit:
game_tread.shutdown_flag.set()
auth_tread.shutdown_flag.set()
game_tread.join()
auth_tread.join()
if __name__ == "__main__":
main()
trd = threading.Thread()
# TODO: разобраться с логгером