M2-PT-DRP/source/managers/RoleManager.py
study-faraphel 9480339b89 improved error handling
instead of having a component crashing, it will issue a warning with the error
2025-02-02 23:31:06 +01:00

35 lines
No EOL
765 B
Python

import traceback
import warnings
from source.behaviors import roles
from source.managers import Manager
class RoleManager:
"""
Role Manager
Responsible for the passive behavior of the machine and sending packets
"""
def __init__(self, manager: "Manager"):
self.manager = manager
# the currently used role
self.current: roles.base.BaseRole = roles.UndefinedRole(self.manager)
def handle(self) -> None:
"""
Run the role
"""
self.current.handle()
def loop(self) -> None:
"""
Handle forever
"""
while True:
try:
self.handle()
except Exception: # NOQA
warnings.warn(traceback.format_exc())