instead of having a component crashing, it will issue a warning with the error
35 lines
No EOL
765 B
Python
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()) |