support exit none driver (#1951)

This commit is contained in:
Ju4tCode 2023-04-27 17:26:59 +08:00 committed by GitHub
parent 6173836bdb
commit 6691f6ef70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -55,16 +55,12 @@ class Driver(BaseDriver):
@overrides(BaseDriver)
def on_startup(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC:
"""
注册一个启动时执行的函数
"""
"""注册一个启动时执行的函数"""
return self._lifespan.on_startup(func)
@overrides(BaseDriver)
def on_shutdown(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC:
"""
注册一个停止时执行的函数
"""
"""注册一个停止时执行的函数"""
return self._lifespan.on_shutdown(func)
@overrides(BaseDriver)
@ -146,7 +142,15 @@ class Driver(BaseDriver):
signal.signal(sig, self._handle_exit)
def _handle_exit(self, sig, frame):
if self.should_exit.is_set():
self.force_exit = True
else:
self.exit(force=self.should_exit.is_set())
def exit(self, force: bool = False):
"""退出 none driver
参数:
force: 强制退出
"""
if not self.should_exit.is_set():
self.should_exit.set()
if force:
self.force_exit = True