From 345c764463c5636727602c695b6e80bbf70a50b3 Mon Sep 17 00:00:00 2001 From: amtoaer Date: Sat, 6 Jan 2024 00:41:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20docker=20=E9=80=80?= =?UTF-8?q?=E5=87=BA=E6=97=B6=E4=B8=8D=E4=BC=9A=E9=87=8A=E6=94=BE=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/entry.py b/entry.py index 48f9c7b..0d41e9d 100644 --- a/entry.py +++ b/entry.py @@ -1,4 +1,6 @@ import asyncio +import os +import signal import sys import uvloop @@ -45,8 +47,18 @@ async def entry() -> None: if __name__ == "__main__": + # 确保 docker 退出时正确触发资源释放 + signal.signal( + signal.SIGTERM, lambda *_: os.kill(os.getpid(), signal.SIGINT) + ) with asyncio.Runner() as runner: try: runner.run(entry()) + except Exception: + logger.exception("Unexpected error occurred, exiting...") + except KeyboardInterrupt: + logger.error("Exit Signal Received, exiting...") finally: + logger.info("Cleaning up resources...") runner.run(cleanup()) + logger.info("Done, exited.")