--- /dev/null
+from . import asyncio
+
+
+__all__ = ["asyncio"]
from typing import Awaitable, Coroutine
-def asyncio_to_thread(func, *args, **kwargs) -> Awaitable:
+def to_thread(func, *args, **kwargs) -> Awaitable:
# version 3.9 and higher, call directly
if sys.version_info.major >= 3 and sys.version_info.minor >= 9:
return asyncio.to_thread(func, *args, **kwargs)
return loop.run_in_executor(None, pfunc)
-def asyncio_create_task(coro: Coroutine, name=None) -> Future:
+def create_task(coro: Coroutine, name=None) -> Future:
# version 3.8 and higher, call directly
if sys.version_info.major >= 3 and sys.version_info.minor >= 8:
return asyncio.create_task(coro, name=name)
return asyncio.ensure_future(coro)
-def asyncio_run(coro: Coroutine, debug=None) -> Awaitable:
+def run(coro: Coroutine, debug=None) -> Awaitable:
# ideally copy-paste of this:
# https://github.com/python/cpython/blob/3.9/Lib/asyncio/runners.py#L8
--- /dev/null
+"""
+This is a compat module that we will use with dataclasses
+due to them being unsupported on Python 3.6. However, a proper backport exists.
+This module is simply a reimport of that backported library (or the system one),
+so that if we have to vendor that library or do something similar with it, we have
+the option to do it transparently, without changing anything else.
+"""
+
+
+from dataclasses import dataclass
+
+
+__all__ = ["dataclass"]
-from dataclasses import dataclass
from typing import Optional
+from .compat.dataclasses import dataclass
from .utils import StrictyamlParser
raise NotImplementedError()
async def start(self):
- await compat.asyncio_to_thread(systemd.start_unit, f"kresd@{self._id}.service")
+ await compat.asyncio.to_thread(systemd.start_unit, f"kresd@{self._id}.service")
async def stop(self):
- await compat.asyncio_to_thread(systemd.stop_unit, f"kresd@{self._id}.service")
+ await compat.asyncio.to_thread(systemd.stop_unit, f"kresd@{self._id}.service")
async def restart(self):
- await compat.asyncio_to_thread(
+ await compat.asyncio.to_thread(
systemd.restart_unit, f"kresd@{self._id}.service"
)
await kresd.stop()
async def _collect_already_running_children(self):
- units = await compat.asyncio_to_thread(systemd.list_units)
+ units = await compat.asyncio.to_thread(systemd.list_units)
for unit in units:
u: str = unit
if u.startswith("kresd@") and u.endswith(".service"):