mirror of
https://github.com/nihilvux/bancho.py.git
synced 2025-09-16 18:48:38 -07:00
Add files via upload
This commit is contained in:
54
app/state/sessions.py
Normal file
54
app/state/sessions.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import Any
|
||||
|
||||
from app.logging import Ansi
|
||||
from app.logging import log
|
||||
from app.objects.collections import Channels
|
||||
from app.objects.collections import Matches
|
||||
from app.objects.collections import Players
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from app.objects.player import Player
|
||||
|
||||
players = Players()
|
||||
channels = Channels()
|
||||
matches = Matches()
|
||||
|
||||
api_keys: dict[str, int] = {}
|
||||
|
||||
housekeeping_tasks: set[asyncio.Task[Any]] = set()
|
||||
|
||||
bot: Player
|
||||
|
||||
|
||||
# use cases
|
||||
|
||||
|
||||
async def cancel_housekeeping_tasks() -> None:
|
||||
log(
|
||||
f"-> Cancelling {len(housekeeping_tasks)} housekeeping tasks.",
|
||||
Ansi.LMAGENTA,
|
||||
)
|
||||
|
||||
# cancel housekeeping tasks
|
||||
for task in housekeeping_tasks:
|
||||
task.cancel()
|
||||
|
||||
await asyncio.gather(*housekeeping_tasks, return_exceptions=True)
|
||||
|
||||
loop = asyncio.get_running_loop()
|
||||
|
||||
for task in housekeeping_tasks:
|
||||
if not task.cancelled():
|
||||
exception = task.exception()
|
||||
if exception:
|
||||
loop.call_exception_handler(
|
||||
{
|
||||
"message": "unhandled exception during loop shutdown",
|
||||
"exception": exception,
|
||||
"task": task,
|
||||
},
|
||||
)
|
Reference in New Issue
Block a user