mirror of
https://github.com/amtoaer/bili-sync.git
synced 2026-09-05 23:49:53 +08:00
fix: 修复 docker 退出时不会释放资源的问题
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
import os
|
||||||
|
import signal
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import uvloop
|
import uvloop
|
||||||
@@ -45,8 +47,18 @@ async def entry() -> None:
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
# 确保 docker 退出时正确触发资源释放
|
||||||
|
signal.signal(
|
||||||
|
signal.SIGTERM, lambda *_: os.kill(os.getpid(), signal.SIGINT)
|
||||||
|
)
|
||||||
with asyncio.Runner() as runner:
|
with asyncio.Runner() as runner:
|
||||||
try:
|
try:
|
||||||
runner.run(entry())
|
runner.run(entry())
|
||||||
|
except Exception:
|
||||||
|
logger.exception("Unexpected error occurred, exiting...")
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
logger.error("Exit Signal Received, exiting...")
|
||||||
finally:
|
finally:
|
||||||
|
logger.info("Cleaning up resources...")
|
||||||
runner.run(cleanup())
|
runner.run(cleanup())
|
||||||
|
logger.info("Done, exited.")
|
||||||
|
|||||||
Reference in New Issue
Block a user