|
import logging |
|
import yaml |
|
|
|
def get_logger(name): |
|
logger = logging.getLogger(name) |
|
logger.setLevel(logging.DEBUG) |
|
handler = logging.StreamHandler() |
|
handler.setLevel(logging.DEBUG) |
|
formatter = logging.Formatter( |
|
"%(asctime)s - %(name)s - %(levelname)s - %(message)s" |
|
) |
|
handler.setFormatter(formatter) |
|
logger.addHandler(handler) |
|
return logger |
|
|
|
def load_yaml(cfg_path): |
|
with open(cfg_path, "r") as file: |
|
cfg = yaml.load(file, Loader=yaml.FullLoader) |
|
return cfg |
|
|
|
class AsyncMixin: |
|
def __init__(self, *args, **kwargs): |
|
""" |
|
Standard constructor used for arguments pass |
|
Do not override. Use __ainit__ instead |
|
""" |
|
self.__storedargs = args, kwargs |
|
self.async_initialized = False |
|
|
|
async def __ainit__(self, *args, **kwargs): |
|
"""Async constructor, you should implement this""" |
|
|
|
async def __initobj(self): |
|
"""Crutch used for __await__ after spawning""" |
|
assert not self.async_initialized |
|
self.async_initialized = True |
|
|
|
await self.__ainit__(*self.__storedargs[0], **self.__storedargs[1]) |
|
return self |
|
|
|
def __await__(self): |
|
return self.__initobj().__await__() |
|
|
|
|