import asyncio import sys import uvicorn import signal from api import * from sockets.socket_server import * import uvicorn.loops.auto import uvicorn.protocols.http.auto import uvicorn.protocols.websockets.auto import uvicorn.lifespan.on from multiprocessing import Process, freeze_support from service.init_load_source import init_load_source def handle_shutdown(signum, frame): """关闭系统应用服务""" # 终止事件循环 loop = asyncio.get_event_loop() loop.call_soon_threadsafe(loop.stop) sys.exit(0) async def run_server(): # 启动uvicorn服务器 isDebug = True if IS_DEBUG == "true" else False config = uvicorn.Config( APP_RUN, host=APP_HOST, port=int(PORT), reload=isDebug, workers=int(APP_WORKS), ) server = uvicorn.Server(config) await server.serve() async def main(): await asyncio.gather(run_server(), init_load_source().load_source()) if __name__ == "__main__": signal.signal(signal.SIGINT, handle_shutdown) signal.signal(signal.SIGTERM, handle_shutdown) print("python server is running at port:", PORT) print("python server is running at port:", APP_RUN) # asyncio.run(main()) isDebug = True if IS_DEBUG == "true" else False uvicorn.run( app=APP_RUN, host=APP_HOST, port=int(PORT), reload=isDebug, loop="auto", )