Skip to content

Commit

Permalink
fix(core): make sure app exits gracefully before shutdown/reboot and …
Browse files Browse the repository at this point in the history
…atexit callbacks run - closes #150
  • Loading branch information
sassanh committed Aug 3, 2024
1 parent 89451e5 commit 5526f1b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- fix(voice): remove the gap between sentences
- fix(core): change the power-off menu item icon - closes #151
- refactor(core): migrate `ubo_app/services.py` to `typings/ubo_handle.pyi` as it was only providing types
- fix(core): make sure app exits gracefully before shutdown/reboot and atexit callbacks run - closes #150

## Version 0.15.5

Expand Down
2 changes: 1 addition & 1 deletion ubo_app/load_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ async def shutdown(self: UboServiceThread) -> None:
if not tasks:
break
for task in tasks:
with contextlib.suppress(asyncio.TimeoutError):
with contextlib.suppress(BaseException):
await asyncio.wait_for(task, timeout=SERVICES_LOOP_GRACE_PERIOD)

logger.debug('Stopping event loop', extra={'thread_': self})
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async def shutdown(self: WorkerThread) -> None:
if not tasks:
break
for task in tasks:
with contextlib.suppress(asyncio.TimeoutError):
with contextlib.suppress(BaseException):
await asyncio.wait_for(task, timeout=MAIN_LOOP_GRACE_PERIOD)

logger.debug('Stopping event loop', extra={'thread_': self})
Expand Down
7 changes: 4 additions & 3 deletions ubo_app/side_effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from pathlib import Path
from typing import TYPE_CHECKING

from kivy.clock import Clock
from redux import FinishAction

from ubo_app.store.core import PowerOffEvent, RebootEvent
Expand Down Expand Up @@ -40,12 +39,13 @@ def power_off() -> None:
if IS_RPI:

def power_off_system(*_: list[object]) -> None:
atexit.unregister(power_off_system)
atexit._run_exitfuncs() # noqa: SLF001
subprocess.run( # noqa: S603
['/usr/bin/env', 'systemctl', 'poweroff', '-i'],
check=True,
)

Clock.schedule_once(power_off_system, 5)
atexit.register(power_off_system)


Expand All @@ -55,12 +55,13 @@ def reboot() -> None:
if IS_RPI:

def reboot_system(*_: list[object]) -> None:
atexit.unregister(reboot_system)
atexit._run_exitfuncs() # noqa: SLF001
subprocess.run( # noqa: S603
['/usr/bin/env', 'systemctl', 'reboot', '-i'],
check=True,
)

Clock.schedule_once(reboot_system, 5)
atexit.register(reboot_system)


Expand Down

0 comments on commit 5526f1b

Please sign in to comment.