diff --git a/beams/logging.py b/beams/logging.py index 482d55a..901fcef 100644 --- a/beams/logging.py +++ b/beams/logging.py @@ -179,11 +179,14 @@ def __init__(self, print_status: bool = False): def run(self, behaviour: Behaviour) -> None: """ - Write node status to logging stream. + Write node status to logging stream, executes AFTER a node is ticked. + (operates on nodes yielded by Behaviour.tick()) + If print_status is requested and the console logger won't display, also - print to console + print to console. """ - out_msg = f"{behaviour.__class__.__name__}.run() [{behaviour.status}]" + name = getattr(behaviour, 'name', None) or behaviour.__class__.__name__ + out_msg = f"{name} node tick completed [{behaviour.status.name}]" if behaviour.feedback_message: logger.debug(out_msg + f": [{behaviour.feedback_message}]") if self.print_status and (self.stream_handler_level > logging.DEBUG): diff --git a/beams/sequencer/helpers/worker.py b/beams/sequencer/helpers/worker.py index 9a5c24a..5b6a859 100644 --- a/beams/sequencer/helpers/worker.py +++ b/beams/sequencer/helpers/worker.py @@ -1,8 +1,8 @@ """ * An base class for child classes whos main function is to support a work thread. -* Holds volatile `self.do_work` which is intended to handle kill signal -* Provides `start_work` and `stop_work` functions to spawn and stop work processes -* Optional constructor arg `stop_func` to be executde on process termination before joining work process. +* Holds volatile `self.do_work` which is intended to handle kill signal. +* Provides `start_work` and `stop_work` functions to spawn and stop work processes. +* Optional arg `stop_func` run on process termination before joining work process. """ import logging from ctypes import c_bool @@ -26,12 +26,12 @@ def __init__( self.proc_name = proc_name self.proc_type = proc_type self.add_args = add_args or [] - # TODO: we may want to decorate work func so it prints proc id... This may be a case of wrapper_func as opposed to decorator if (work_func is None): self.work_proc = proc_type(target=self.work_func, name=self.proc_name) else: self.work_func = work_func - # Critical Note: This makes assumptions of the work_func signature in that it takes a Value argument in position 0 + # Critical Note: This makes assumptions of the work_func signature + # in that it takes a Value argument in position 0 self.work_proc = proc_type(target=self.work_func, name=self.proc_name, args=(self.do_work, *self.add_args,)) @@ -39,28 +39,28 @@ def __init__( def start_work(self): if self.do_work.value: - logger.error("Already working, not starting work") + logger.error(f"({self.proc_name}) -->>: Already working, cannot start") return self.do_work.value = True self.work_proc.start() - logger.debug("Starting work") + logger.debug(f"({self.proc_name}) -->>: Starting work") def stop_work(self): - logger.debug(f"Calling stop work on {self.proc_name}") + logger.debug(f"({self.proc_name}) -->>: Calling stop work") if not self.do_work.value: - logger.error(f"Not working, not stopping work on {self.proc_name}") + logger.error(f"({self.proc_name}) -->>: Not working, not stopping work") return self.do_work.value = False - logger.debug(f"Sending terminate signal to process {self.proc_name} : {self.work_proc.pid}") + logger.debug(f"({self.proc_name}) -->>: Sending terminate signal to process") # Send kill signal to work process. # TODO: the exact location of this # is important. Reflect with self.do_work.get_lock(): self.work_proc.terminate() if (self.stop_func is not None): self.stop_func() - logger.debug(f"Ending work, calling join on {self.proc_name}") + logger.debug(f"({self.proc_name}) -->>: Ending work, calling join") self.work_proc.join() - logger.debug(f"Worker process joined from {self.proc_name}") + logger.debug(f"({self.proc_name}) -->>: Worker process joined") def work_func(self): """