implemented shutdown-tasks

This commit is contained in:
Eric 2023-08-23 19:41:33 -07:00
parent a8e4def970
commit 4cf54d4f85
No known key found for this signature in database
GPG Key ID: 89C93F0F8D6D5A98
5 changed files with 68 additions and 39 deletions

40
.efrocachemap generated
View File

@ -4064,26 +4064,26 @@
"build/assets/windows/Win32/ucrtbased.dll": "2def5335207d41b21b9823f6805997f1",
"build/assets/windows/Win32/vc_redist.x86.exe": "b08a55e2e77623fe657bea24f223a3ae",
"build/assets/windows/Win32/vcruntime140d.dll": "865b2af4d1e26a1a8073c89acb06e599",
"build/prefab/full/linux_arm64_gui/debug/ballisticakit": "555b3503d71eb09474d49553a488e6c1",
"build/prefab/full/linux_arm64_gui/release/ballisticakit": "bd20bb96bec6b13aa430e70af14331f6",
"build/prefab/full/linux_arm64_server/debug/dist/ballisticakit_headless": "89b7a281b1cafff201fef5cb1c629bb5",
"build/prefab/full/linux_arm64_server/release/dist/ballisticakit_headless": "fa95541295ff25b97d0b9723091a4fce",
"build/prefab/full/linux_x86_64_gui/debug/ballisticakit": "6cac4dfcd13dbbae87a151fc8294d9aa",
"build/prefab/full/linux_x86_64_gui/release/ballisticakit": "2ea050ccfcb0259731311113f2515241",
"build/prefab/full/linux_x86_64_server/debug/dist/ballisticakit_headless": "0dc43ad6256f00d7182a978288bfe5c8",
"build/prefab/full/linux_x86_64_server/release/dist/ballisticakit_headless": "2abf8ddfd7fc730b3e0441f0c171cdbe",
"build/prefab/full/mac_arm64_gui/debug/ballisticakit": "498518ae4104b10f41959bd998c5584a",
"build/prefab/full/mac_arm64_gui/release/ballisticakit": "0d82a75cea7b1949c77f42b466da35bf",
"build/prefab/full/mac_arm64_server/debug/dist/ballisticakit_headless": "fc8703153f95a985b38de006629cd533",
"build/prefab/full/mac_arm64_server/release/dist/ballisticakit_headless": "3f0990bd2c1889f4699ebf53b8aaef11",
"build/prefab/full/mac_x86_64_gui/debug/ballisticakit": "c4c9eec7ff72837117bef90328ab2316",
"build/prefab/full/mac_x86_64_gui/release/ballisticakit": "d85c6e89f33f3b473d8e6a7bae60dd51",
"build/prefab/full/mac_x86_64_server/debug/dist/ballisticakit_headless": "e47d714d1c27d8419d281941e5ba3d6d",
"build/prefab/full/mac_x86_64_server/release/dist/ballisticakit_headless": "efc3fdb8cb42557d4aceb45c6121bc92",
"build/prefab/full/windows_x86_gui/debug/BallisticaKit.exe": "b3f3ab6a1b8244dbdacea67391e62a3e",
"build/prefab/full/windows_x86_gui/release/BallisticaKit.exe": "3d0b4315998100591a6b7020584491ef",
"build/prefab/full/windows_x86_server/debug/dist/BallisticaKitHeadless.exe": "806b83a7e0351c0dec58090de090ef75",
"build/prefab/full/windows_x86_server/release/dist/BallisticaKitHeadless.exe": "29d2dd63013dfd333eeac281d71f1626",
"build/prefab/full/linux_arm64_gui/debug/ballisticakit": "2ce43921f1917e4face2bd89de255c89",
"build/prefab/full/linux_arm64_gui/release/ballisticakit": "cfad36d58003989bd3fb758d72900914",
"build/prefab/full/linux_arm64_server/debug/dist/ballisticakit_headless": "11a8f7317dafd295f43e5b8573b21caa",
"build/prefab/full/linux_arm64_server/release/dist/ballisticakit_headless": "dca6448b3d8f3acd46632f103d270b38",
"build/prefab/full/linux_x86_64_gui/debug/ballisticakit": "dcf48e1ee93b7a747b0c33efca58057a",
"build/prefab/full/linux_x86_64_gui/release/ballisticakit": "b568da36b6a2ee329e31ff321df54810",
"build/prefab/full/linux_x86_64_server/debug/dist/ballisticakit_headless": "b9e6b511c5fea84b0a81335fd3000592",
"build/prefab/full/linux_x86_64_server/release/dist/ballisticakit_headless": "ec94eec1e4c1084535c65e9923de87d6",
"build/prefab/full/mac_arm64_gui/debug/ballisticakit": "d53c169951686dd96a85668def6dbbfc",
"build/prefab/full/mac_arm64_gui/release/ballisticakit": "b46e409cb87de94f6cf6f7d3e10e032f",
"build/prefab/full/mac_arm64_server/debug/dist/ballisticakit_headless": "4692a22e7ddaf15e34157325252b5fb3",
"build/prefab/full/mac_arm64_server/release/dist/ballisticakit_headless": "d0ab73deaa89dd9fa1b75c65d463d293",
"build/prefab/full/mac_x86_64_gui/debug/ballisticakit": "3db746bb01e002fee667c70c6f57f928",
"build/prefab/full/mac_x86_64_gui/release/ballisticakit": "10c06bd2c02a9b2ac488993e2ffc6700",
"build/prefab/full/mac_x86_64_server/debug/dist/ballisticakit_headless": "01a466465933b84f3772e9d274ee9c40",
"build/prefab/full/mac_x86_64_server/release/dist/ballisticakit_headless": "3d3233606e03eb3b8ffe04169a5f2fce",
"build/prefab/full/windows_x86_gui/debug/BallisticaKit.exe": "c59aeaf8686b4008d0b11728a0523397",
"build/prefab/full/windows_x86_gui/release/BallisticaKit.exe": "92dcffd261cfe8bf80806ebc765bb323",
"build/prefab/full/windows_x86_server/debug/dist/BallisticaKitHeadless.exe": "57639e6862d409cf39ad2fd609aafb20",
"build/prefab/full/windows_x86_server/release/dist/BallisticaKitHeadless.exe": "fa7a86c50be523dcb7ff6aadb9d79d0e",
"build/prefab/lib/linux_arm64_gui/debug/libballisticaplus.a": "d16860bc4d3ff0abae745e2fd5638149",
"build/prefab/lib/linux_arm64_gui/release/libballisticaplus.a": "620ed03a89ad8053656a466da6053676",
"build/prefab/lib/linux_arm64_server/debug/libballisticaplus.a": "d16860bc4d3ff0abae745e2fd5638149",

View File

@ -1,4 +1,4 @@
### 1.7.26 (build 21248, api 8, 2023-08-23)
### 1.7.26 (build 21250, api 8, 2023-08-23)
- Android should now be better at detecting hardware keyboards (you will see
'Configure Keyboard' and 'Configure Keyboard P2' buttons under
@ -29,6 +29,8 @@
properly closing the audio system when shutting down. It also means there
should be more consistent use of the 'Quit?' confirm window. Please holler if
you see any odd behavior when trying to quit the app.
- Added `ba.app.add_shutdown_task()` to register coroutines to be run as part of
shutdown.
- Removed `babase.app.iircade_mode`. RIP iiRcade :(.
### 1.7.25 (build 21211, api 8, 2023-08-03)

View File

@ -23,7 +23,7 @@ from babase._appintent import AppIntentDefault, AppIntentExec
if TYPE_CHECKING:
import asyncio
from typing import Any, Callable
from typing import Any, Callable, Coroutine
from concurrent.futures import Future
import babase
@ -241,16 +241,16 @@ class App:
self._subsystems: list[AppSubsystem] = []
self._native_bootstrapped = False
self._called_on_app_launching = False
self._native_paused = False
self._native_shutdown_called = False
self._launch_completed = False
self._initial_sign_in_completed = False
self._meta_scan_completed = False
self._called_on_app_launching = False
self._called_on_app_loading = False
self._called_on_app_running = False
self._paused = False
self._subsystem_registration_ended = False
self._pending_apply_app_config = False
self._shutdown_called = False
# Config.
self.config_file_healthy = False
@ -290,6 +290,7 @@ class App:
self._intent: AppIntent | None = None
self._mode: AppMode | None = None
self._shutdown_task: asyncio.Task[None] | None = None
self._shutdown_tasks: list[Coroutine[None, None, None]] = []
# Controls which app-modes we use for handling given
# app-intents. Plugins can override this to change high level
@ -704,13 +705,13 @@ class App:
assert _babase.in_logic_thread()
# Can't shut down until we've got our asyncio machinery spun up.
if self._shutdown_called and self._aioloop is not None:
if self._native_shutdown_called and self._aioloop is not None:
# Entering shutdown state:
if self.state is not self.State.SHUTTING_DOWN:
self.state = self.State.SHUTTING_DOWN
self._on_app_shutdown()
elif self._paused:
elif self._native_paused:
# Entering paused state:
if self.state is not self.State.PAUSED:
self.state = self.State.PAUSED
@ -746,17 +747,43 @@ class App:
self._called_on_app_launching = True
self._on_app_launching()
def add_shutdown_task(self, coro: Coroutine[None, None, None]) -> None:
"""Add a task to be run on app shutdown."""
if self.state is self.State.SHUTTING_DOWN:
raise RuntimeError(
'Cannot add shutdown tasks with state SHUTTING_DOWN.'
)
self._shutdown_tasks.append(coro)
async def _shutdown(self) -> None:
import asyncio
try:
# print('SHUTDOWN BEGIN')
await asyncio.sleep(0.0)
# print('SHUTDOWN END')
except Exception:
logging.exception('Error during shutdown.')
async with asyncio.TaskGroup() as task_group:
for task_coro in self._shutdown_tasks:
# Note: Mypy currently complains if we don't take
# this return value, but we don't actually need to.
# https://github.com/python/mypy/issues/15036
_ = task_group.create_task(
self._run_shutdown_task(task_coro)
)
except* Exception:
logging.exception('Unexpected error(s) in shutdown.')
_babase.complete_shutdown()
async def _run_shutdown_task(
self, coro: Coroutine[None, None, None]
) -> None:
"""Run a shutdown task; report errors and abort if taking too long."""
import asyncio
task = asyncio.create_task(coro)
try:
await asyncio.wait_for(task, 5.0)
except Exception:
logging.exception('Error in shutdown task.')
def on_native_bootstrapped(self) -> None:
"""Called by the native layer once its ready to rock."""
assert _babase.in_logic_thread()
@ -767,21 +794,21 @@ class App:
def on_native_pause(self) -> None:
"""Called by the native layer when the app pauses."""
assert _babase.in_logic_thread()
assert not self._paused # Should avoid redundant calls.
self._paused = True
assert not self._native_paused # Should avoid redundant calls.
self._native_paused = True
self._update_state()
def on_native_resume(self) -> None:
"""Called by the native layer when the app resumes."""
assert _babase.in_logic_thread()
assert self._paused # Should avoid redundant calls.
self._paused = False
assert self._native_paused # Should avoid redundant calls.
self._native_paused = False
self._update_state()
def on_native_shutdown(self) -> None:
"""Called by the native layer when the app starts shutting down."""
assert _babase.in_logic_thread()
self._shutdown_called = True
self._native_shutdown_called = True
self._update_state()
def _on_app_pause(self) -> None:

View File

@ -52,7 +52,7 @@ if TYPE_CHECKING:
# Build number and version of the ballistica binary we expect to be
# using.
TARGET_BALLISTICA_BUILD = 21248
TARGET_BALLISTICA_BUILD = 21250
TARGET_BALLISTICA_VERSION = '1.7.26'

View File

@ -39,7 +39,7 @@ auto main(int argc, char** argv) -> int {
namespace ballistica {
// These are set automatically via script; don't modify them here.
const int kEngineBuildNumber = 21248;
const int kEngineBuildNumber = 21250;
const char* kEngineVersion = "1.7.26";
#if BA_MONOLITHIC_BUILD