-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlauncher.py
49 lines (41 loc) · 1.19 KB
/
launcher.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
#from http.server import BaseHTTPRequestHandler, HTTPServer
#import json
#
#port = 8075 # BOTS
#class Handler(BaseHTTPRequestHandler):
# def do_POST(self):
# obj = json.loads(self.rfile.read().decode('utf-8', 'ignore'))
# import pprint
# pprint.pprint(obj)
#
#server = HTTPServer(('', port), Handler)
#server.serve_forever()
from multiprocessing import Process, Pipe
import threading, time
import signal
def runBody(queue):
import bot
bot.mainLoop(queue)
def keepBodyAlive(state, pipe):
while state["running"]:
print("keeyBodyAlive")
p = Process(target=runBody, args=(child,))
state["proc"] = p
p.start()
p.join()
time.sleep(5)
print("keepBodyAlive exits")
if __name__ == "__main__":
state = {"running": True, "proc": None}
pipe, child = Pipe()
def onsignal(signal, frame):
print("Caught signal", state)
state["running"] = False
pipe.close()
child.close()
state["proc"].terminate()
signal.signal(signal.SIGINT, onsignal)
threading.Thread(target=keepBodyAlive,
args=(state, child)).start()
import connector
connector.mainLoop(pipe, state)