File: SynchronousQueue.py

package info (click to toggle)
python-applicationinsights 0.11.10-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 876 kB
  • sloc: python: 5,948; makefile: 151; sh: 77
file content (31 lines) | stat: -rw-r--r-- 1,074 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from .QueueBase import QueueBase

class SynchronousQueue(QueueBase):
    """A synchronous queue for use in conjunction with the :class:`SynchronousSender`. The queue will call
    :func:`send` on :func:`sender` when it reaches :func:`max_queue_length`, or when the consumer calls
    :func:`flush`.

    .. code:: python

        from application_insights.channel import SynchronousQueue
        queue = SynchronousQueue(None)
        queue.max_queue_length = 1
        queue.put(1)
    """
    def flush(self):
        """Flushes the current queue by by calling :func:`sender`'s :func:`send` method.
        """
        local_sender = self.sender
        if not local_sender:
            return
        while True:
            # get at most send_buffer_size items and send them
            data = []
            while len(data) < local_sender.send_buffer_size:
                item = self.get()
                if not item:
                    break
                data.append(item)
            if len(data) == 0:
                break
            local_sender.send(data)