How to use the priority.PriorityTree function in priority

To help you get started, we’ve selected a few priority examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github python-hyper / priority / test / test_priority.py View on Github external
def __init__(self):
        super(PriorityStateMachine, self).__init__()
        self.tree = priority.PriorityTree()
        self.stream_ids = set([0])
        self.blocked_stream_ids = set()
github python-hyper / priority / test / test_priority.py View on Github external
def test_priority_raises_good_errors_for_missing_streams(self):
        """
        Attempting operations on absent streams raises a MissingStreamError.
        """
        p = priority.PriorityTree()
        p.insert_stream(1)

        with pytest.raises(priority.MissingStreamError):
            p.reprioritize(3)

        with pytest.raises(priority.MissingStreamError):
            p.block(3)

        with pytest.raises(priority.MissingStreamError):
            p.unblock(3)

        with pytest.raises(priority.MissingStreamError):
            p.remove_stream(3)
github python-hyper / priority / test / test_priority.py View on Github external
def readme_tree():
    """
    Provide a tree configured as the one in the readme.
    """
    p = priority.PriorityTree()
    p.insert_stream(stream_id=1)
    p.insert_stream(stream_id=3)
    p.insert_stream(stream_id=5, depends_on=1)
    p.insert_stream(stream_id=7, weight=32)
    p.insert_stream(stream_id=9, depends_on=7, weight=8)
    p.insert_stream(stream_id=11, depends_on=7, exclusive=True)
    return p
github python-hyper / priority / test / test_priority.py View on Github external
def test_priority_raises_good_errors_for_zero_stream(self):
        """
        Attempting operations on stream 0 raises a PseudoStreamError.
        """
        p = priority.PriorityTree()
        p.insert_stream(1)

        with pytest.raises(priority.PseudoStreamError):
            p.reprioritize(0)

        with pytest.raises(priority.PseudoStreamError):
            p.block(0)

        with pytest.raises(priority.PseudoStreamError):
            p.unblock(0)

        with pytest.raises(priority.PseudoStreamError):
            p.remove_stream(0)
github python-hyper / priority / test / test_priority.py View on Github external
def test_priority_tree_raises_error_inserting_duplicate(self):
        """
        Attempting to insert a stream that is already in the tree raises a
        DuplicateStreamError
        """
        p = priority.PriorityTree()
        p.insert_stream(1)

        with pytest.raises(priority.DuplicateStreamError):
            p.insert_stream(1)
github python-hyper / priority / test / test_priority.py View on Github external
def test_period_of_repetition(self, streams_and_weights):
        """
        The period of repetition of a priority sequence is given by the sum of
        the weights of the streams. Once that many values have been pulled out
        the sequence repeats identically.
        """
        p = priority.PriorityTree()
        weights = []

        for stream, weight in streams_and_weights:
            p.insert_stream(stream_id=stream, weight=weight)
            weights.append(weight)

        period = sum(weights)

        # Pop off the first n elements, which will always be evenly
        # distributed.
        for _ in weights:
            next(p)

        pattern = [next(p) for _ in range(period)]
        pattern = itertools.cycle(pattern)
github twisted / twisted / src / twisted / web / _http2.py View on Github external
def __init__(self, reactor=None):
        config = h2.config.H2Configuration(
            client_side=False, header_encoding=None
        )
        self.conn = h2.connection.H2Connection(config=config)
        self.streams = {}

        self.priority = priority.PriorityTree()
        self._consumerBlocked = None
        self._sendingDeferred = None
        self._outboundStreamQueues = {}
        self._streamCleanupCallbacks = {}
        self._stillProducing = True

        # Limit the number of buffered control frame (e.g. PING and
        # SETTINGS) bytes.
        self._maxBufferedControlFrameBytes = 1024 * 17
        self._bufferedControlFrames = deque()
        self._bufferedControlFrameBytes = 0

        if reactor is None:
            from twisted.internet import reactor
        self._reactor = reactor
github pgjones / hypercorn / hypercorn / protocol / h2.py View on Github external
initial_values={
                h2.settings.SettingCodes.MAX_CONCURRENT_STREAMS: config.h2_max_concurrent_streams,
                h2.settings.SettingCodes.MAX_HEADER_LIST_SIZE: config.h2_max_header_list_size,
                h2.settings.SettingCodes.ENABLE_CONNECT_PROTOCOL: 1,
            },
        )

        self.event_class = event_class
        self.send = send
        self.server = server
        self.spawn_app = spawn_app
        self.ssl = ssl
        self.streams: Dict[int, Union[HTTPStream, WSStream]] = {}
        # The below are used by the sending task
        self.has_data = event_class()
        self.priority = priority.PriorityTree()
        self.stream_buffers: Dict[int, StreamBuffer] = {}
github decentfox / aioh2 / aioh2 / protocol.py View on Github external
def __init__(self, client_side: bool, *, loop=None,
                 concurrency=8, functional_timeout=2):
        if loop is None:
            loop = asyncio.get_event_loop()
        self._loop = loop
        self._conn = H2Connection(config=H2Configuration(client_side=client_side))
        self._transport = None
        self._streams = {}
        self._inbound_requests = asyncio.Queue(concurrency, loop=loop)
        self._priority = priority.PriorityTree()
        self._priority_events = {}

        # Locks

        self._is_resumed = False
        self._resumed = CallableEvent(lambda: self._is_resumed, loop=loop)
        self._stream_creatable = CallableEvent(self._is_stream_creatable,
                                               loop=loop)
        self._last_active = 0
        self._ping_index = -1
        self._ping_time = 0
        self._rtt = None
        self._functional_timeout = functional_timeout
        self._functional = CallableEvent(self._is_functional, loop=loop)

        # Dispatch table
github encode / uvicorn / uvicorn / protocols / http / h2_impl.py View on Github external
self.client = None
        self.scheme = None

        # HTTP/2 specific states
        self.streams = defaultdict(
            lambda: {
                # Per-request states
                # TODO use dataclass instead? they'll be a bit slower tho (w/o slots)
                "scope": None,
                "headers": None,
                "cycle": None,
                "message_event": asyncio.Event(),
                "flow": None,
            }
        )  # So we can store the data per the stream id
        self.priority = priority.PriorityTree()