Пример #1
0
def del_chan_at_id(chan_name, chan_id) -> None:
    """
    Delete the channel instance that matches the name and the id
    :param chan_name: the channel name
    :param chan_id: the channel id
    """
    try:
        ChannelInstances.instance().channels[chan_id].pop(chan_name, None)
    except KeyError:
        logging.get_logger(ChannelInstances.__name__).warning(
            f"Can't del chan {chan_name} with chan_id: {chan_id}")
Пример #2
0
    def __init__(
        self,
        callback: object,
        size: int = async_channel.constants.DEFAULT_QUEUE_SIZE,
        priority_level: int = async_channel.enums.
        ChannelConsumerPriorityLevels.HIGH.value,
    ):
        self.logger = logging.get_logger(self.__class__.__name__)

        # Consumer data queue. It contains producer's work (received through Producer.send()).
        self.queue = asyncio.Queue(maxsize=size)

        # Method to be called when performing task is done
        self.callback = callback

        # Should only be used with .cancel()
        self.consume_task = None
        """
        Should be used as the perform while loop condition
            >>> while(self.should_stop):
                    ...
        """
        self.should_stop = False

        # Default priority level
        # Used by Producers to call consumers by prioritization
        # The lowest level has the highest priority
        self.priority_level = priority_level
Пример #3
0
    def __init__(self, channel):
        self.logger = logging.get_logger(self.__class__.__name__)

        # Related async_channel instance
        self.channel = channel
        """
        Should only be used with .cancel()
        """
        self.produce_task = None
        """
        Should be used as the perform while loop condition
            while(self.should_stop):
                ...
        """
        self.should_stop = False
        """
        Should be used to know if the producer is already started
        """
        self.is_running = False
Пример #4
0
    def __init__(self):
        self.logger = logging.get_logger(self.__class__.__name__)

        # Channel unique id
        self.chan_id = None

        # Channel subscribed producers list
        self.producers = []

        # Channel subscribed consumers list
        self.consumers = []

        # Used to perform global send from non-producer context
        self.internal_producer = None

        # Used to save producers state (paused or not)
        self.is_paused = True

        # Used to synchronize producers and consumer
        self.is_synchronized = False