forked from CodersClashS01/Kryptonite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.py
35 lines (28 loc) · 1.12 KB
/
start.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
import io
import os
import subprocess
from pathlib import Path
from threading import Thread
base = Path(__file__).parent.resolve()
website_path = base / 'website'
my_env = os.environ.copy()
my_env['PYTHONPATH'] = ':'.join([str(base)] + [path for path in my_env.get('PYTHONPATH', '').split(':') if path])
def run_website():
proc = subprocess.Popen(["flask", "run"], cwd=str(website_path), stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
env=my_env)
for line in io.TextIOWrapper(proc.stdout, encoding="utf-8"):
if line.strip():
print("website:", line.strip('\n'))
def run_bot():
proc = subprocess.Popen(["python", "main.py"], cwd=str(base), stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
env=my_env)
for line in io.TextIOWrapper(proc.stdout, encoding="utf-8"):
if line.strip():
print("bot :", line.strip('\n'))
if __name__ == '__main__':
website_thread = Thread(target=run_website)
bot_thread = Thread(target=run_bot)
website_thread.start()
bot_thread.start()
website_thread.join()
bot_thread.join()