Exemplo n.º 1
0
    def _message_handle(self, message: Message):
        """Takes a slightly different approach to messages as it needs to handle
        different situations"""

        # Run garbage collection
        self.garbage_collect()

        self.logger.debug(
            f"MESSAGE Sender: {message.sender}, Command {message.command}, Package: {message.package}"
        )

        # Addressed to self
        if message.receiver == [self.name]:
            # Process as normal
            super()._message_handle(message)
        # Addressed to child thread
        elif self.name in message.receiver:
            # Strip name off front and pass on
            message.receiver = message.receiver[1:]
            # Send to appropriate thread input queue
            if message.receiver[0] in self.active_threads.keys():
                self.active_threads[message.receiver[0]].input_queue.put(
                    message)
        else:
            # Check sender is not in list of destroyed threads
            if len(message.sender) > 1:
                if message.sender[1] not in self.destroyed_threads:
                    # Append name to front of sender and pass up
                    message.sender = [self.owner, *message.sender]
                    self.output_queue.put(message)
                else:
                    self.logger.error(
                        f"Sender {message.sender[1]} is a destroyed thread")
            else:
                self.logger.error(
                    f"Sender {message.sender} does not have enough information"
                )

        # Run garbage collection
        self.garbage_collect()
Exemplo n.º 2
0
    def _message_handle(self, message: Message):
        """Based on ThreadManager approach to handling messages from the outside
        and from children
        Have to do some things manually as they do not have scope for the new functions
        when being used from super
        """
        self.logger.debug(
            f"MESSAGE Sender: {message.sender}, Command {message.command}, Package: {message.package}"
        )

        # Addressed to self
        if message.receiver == self.name or message.receiver == [self.name]:
            # Process as normal
            super()._message_handle(message)
        # Addressed to screen
        elif self.name in message.receiver:
            # Strip name off front and pass on
            message.receiver = message.receiver[1:]
            # If the screen is active pass the message
            # Should inactive screens be able to receive messsages?
            if message.receiver[0] in self.active_screens:
                self.screens[message.receiver[0]].update(message)
        else:
            self.process_outgoing_messsages(message)