polymer/Polymer.py
def message_loop(self, t_q, r_q):
        """Loop through messages and execute tasks"""
        t_msg = {}
        while t_msg.get("state", "") != "__DIE__":
            try:
                t_msg = t_q.get(True, self.cycle_sleep)  # Poll blocking
                self.task = t_msg.get("task", "")  # __DIE__ has no task
                if self.task != "":

                    self.task.task_start = time.time()  # Start the timer
                    # Send ACK to the controller who requested work on this task
                    self.r_q_send(
                        {"w_id": self.w_id, "task": self.task, "state": "__ACK__"}
                    )

                    # Update the sleep time with latest recommendations
                    self.cycle_sleep = self.task.worker_loop_delay

                    # Assign the result of task.run() to task.result
                    self.task.result = self.task.run()
                    self.task.task_stop = time.time()  # Seconds since epoch

                    self.r_q_send(
                        {"w_id": self.w_id, "task": self.task, "state": "__FINISHED__"}
                    )  # Ack work finished

                    self.task = None
            except Empty:
                pass
            except Full:
                time.sleep(0.1)
            ## Disable extraneous error handling...
            except:
                if self.task is not None:
                    self.task.task_stop = time.time()  # Seconds since epoch
                # Handle all other errors here...
                tb_str = "".join(tb.format_exception(*(sys.exc_info())))
                self.r_q_send(
                    {
                        "w_id": self.w_id,
                        "task": self.task,
                        "error": tb_str,
                        "state": "__ERROR__",
                    }
                )

        return
def message_loop(self, t_q, r_q):
        """Loop through messages and execute tasks"""
        t_msg = {}
        while t_msg.get("state", "") != "__DIE__":
            try:
                t_msg = t_q.get(True, self.cycle_sleep)  # Poll blocking
                self.task = t_msg.get("task", "")  # __DIE__ has no task
                if self.task != "":

                    self.task.task_start = time.time()  # Start the timer
                    # Send ACK to the controller who requested work on this task
                    self.r_q_send(
                        {"w_id": self.w_id, "task": self.task, "state": "__ACK__"}
                    )

                    # Update the sleep time with latest recommendations
                    self.cycle_sleep = self.task.worker_loop_delay

                    # Assign the result of task.run() to task.result
                    self.task.result = self.task.run()
                    self.task.task_stop = time.time()  # Seconds since epoch

                    self.r_q_send(
                        {"w_id": self.w_id, "task": self.task, "state": "__FINISHED__"}
                    )  # Ack work finished

                    self.task = None
            except Empty:
                pass
            except Full:
                time.sleep(0.1)
            ## Disable extraneous error handling...
            except:
                if self.task is not None:
                    self.task.task_stop = time.time()  # Seconds since epoch
                # Handle all other errors here...
                tb_str = "".join(tb.format_exception(*(sys.exc_info())))
                self.r_q_send(
                    {
                        "w_id": self.w_id,
                        "task": self.task,
                        "error": tb_str,
                        "state": "__ERROR__",
                    }
                )

        return
def message_loop ( self , t_q , r_q ) : t_msg = { } while t_msg . get ( "state" , "" ) != "__DIE__" : try : t_msg = t_q . get ( True , self . cycle_sleep ) # Poll blocking self . task = t_msg . get ( "task" , "" ) # __DIE__ has no task if self . task != "" : self . task . task_start = time . time ( ) # Start the timer # Send ACK to the controller who requested work on this task self . r_q_send ( { "w_id" : self . w_id , "task" : self . task , "state" : "__ACK__" } ) # Update the sleep time with latest recommendations self . cycle_sleep = self . task . worker_loop_delay # Assign the result of task.run() to task.result self . task . result = self . task . run ( ) self . task . task_stop = time . time ( ) # Seconds since epoch self . r_q_send ( { "w_id" : self . w_id , "task" : self . task , "state" : "__FINISHED__" } ) # Ack work finished self . task = None except Empty : pass except Full : time . sleep ( 0.1 ) ## Disable extraneous error handling... except : if self . task is not None : self . task . task_stop = time . time ( ) # Seconds since epoch # Handle all other errors here... tb_str = "" . join ( tb . format_exception ( * ( sys . exc_info ( ) ) ) ) self . r_q_send ( { "w_id" : self . w_id , "task" : self . task , "error" : tb_str , "state" : "__ERROR__" , } ) return
Loop through messages and execute tasks
Loop through messages and execute tasks