mirror of
https://github.com/amtoaer/bili-sync.git
synced 2026-06-28 02:42:25 +08:00
fix: 修复 docker 退出时不会释放资源的问题
This commit is contained in:
12
entry.py
12
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.")
|
||||
|
||||
Reference in New Issue
Block a user