2022-06-03 16:00:33 +08:00
|
|
|
import threading
|
2022-06-03 23:00:54 +08:00
|
|
|
from multiprocessing import Event, Process
|
2022-01-07 22:06:28 +08:00
|
|
|
|
2022-06-04 17:40:26 +08:00
|
|
|
from module.webui.setting import State
|
|
|
|
|
2022-01-07 22:06:28 +08:00
|
|
|
|
2022-06-03 16:00:33 +08:00
|
|
|
def func(ev: threading.Event):
|
|
|
|
import argparse
|
2022-06-03 23:00:54 +08:00
|
|
|
import asyncio
|
|
|
|
import sys
|
|
|
|
|
2022-06-03 16:00:33 +08:00
|
|
|
import uvicorn
|
2022-06-03 23:00:54 +08:00
|
|
|
|
|
|
|
if sys.platform.startswith("win"):
|
|
|
|
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
|
|
|
|
|
2022-06-03 16:00:33 +08:00
|
|
|
State.researt_event = ev
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description="Alas web service")
|
|
|
|
parser.add_argument(
|
|
|
|
"--host",
|
|
|
|
type=str,
|
|
|
|
help="Host to listen. Default to WebuiHost in deploy setting",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"-p",
|
|
|
|
"--port",
|
|
|
|
type=int,
|
|
|
|
help="Port to listen. Default to WebuiPort in deploy setting",
|
|
|
|
)
|
2022-01-08 21:45:05 +08:00
|
|
|
args, _ = parser.parse_known_args()
|
2022-01-07 22:06:28 +08:00
|
|
|
|
2022-06-03 21:28:44 +08:00
|
|
|
host = args.host or State.deploy_config.WebuiHost or "0.0.0.0"
|
|
|
|
port = args.port or int(State.deploy_config.WebuiPort) or 22267
|
2022-01-07 22:06:28 +08:00
|
|
|
|
2022-06-04 17:40:26 +08:00
|
|
|
uvicorn.run("module.webui.app:app", host=host, port=port, factory=True)
|
2022-01-07 22:06:28 +08:00
|
|
|
|
2022-06-03 18:54:54 +08:00
|
|
|
|
2022-06-03 16:00:33 +08:00
|
|
|
if __name__ == "__main__":
|
2022-06-04 17:40:26 +08:00
|
|
|
if State.deploy_config.EnableReload:
|
|
|
|
should_exit = False
|
2022-06-03 18:54:54 +08:00
|
|
|
while not should_exit:
|
2022-06-04 17:40:26 +08:00
|
|
|
event = Event()
|
|
|
|
process = Process(target=func, args=(event,))
|
|
|
|
process.start()
|
|
|
|
while not should_exit:
|
|
|
|
if event.wait(5):
|
|
|
|
process.kill()
|
|
|
|
break
|
|
|
|
elif process.is_alive():
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
should_exit = True
|
|
|
|
else:
|
|
|
|
func(None)
|