예제 #1
0
    def test_send_timeout(self, gsock, server_sock):
        resize_buffer(server_sock, 1)
        evt = Event()

        def server():
            client_sock, addr = server_sock.accept()
            resize_buffer(client_sock, 1)
            evt.wait()

        g = spawn(server)

        server_addr = server_sock.getsockname()
        resize_buffer(gsock, 1)
        gsock.connect(server_addr)
        gsock.settimeout(TIMEOUT_SMALL)

        with pytest.raises(socket.timeout):
            # large enough data to overwhelm most buffers
            msg_len = 10 ** 6
            sent = 0

            while sent < msg_len:
                sent += gsock.send(bytes(msg_len))

        evt.send()
        g.wait()
예제 #2
0
파일: test_greenio.py 프로젝트: dmdm/guv
    def test_send_timeout(self, gsock, server_sock):
        resize_buffer(server_sock, 1)
        evt = Event()

        def server():
            client_sock, addr = server_sock.accept()
            resize_buffer(client_sock, 1)
            evt.wait()

        g = spawn(server)

        server_addr = server_sock.getsockname()
        resize_buffer(gsock, 1)
        gsock.connect(server_addr)
        gsock.settimeout(TIMEOUT_SMALL)

        with pytest.raises(socket.timeout):
            # large enough data to overwhelm most buffers
            msg_len = 10 ** 6
            sent = 0

            while sent < msg_len:
                sent += gsock.send(bytes(msg_len))

        evt.send()
        g.wait()
예제 #3
0
파일: queue.py 프로젝트: PlumpMath/guv
class Queue(LightQueue):
    """Create a queue object with a given maximum size

    If `maxsize` is less than zero or ``None``, the queue size is infinite.

    ``Queue(0)`` is a channel, that is, its :meth:`put` method always blocks until the item is
    delivered. (This is unlike the standard :class:`queue.Queue`, where 0 means infinite size).

    In all other respects, this Queue class resembles the standard library, :class:`queue.Queue`.
    """
    def __init__(self, maxsize=None):
        LightQueue.__init__(self, maxsize)
        self.unfinished_tasks = 0
        self._cond = Event()

    def _format(self):
        result = LightQueue._format(self)
        if self.unfinished_tasks:
            result += ' tasks=%s _cond=%s' % (self.unfinished_tasks,
                                              self._cond)
        return result

    def _put(self, item):
        LightQueue._put(self, item)
        self._put_bookkeeping()

    def _put_bookkeeping(self):
        self.unfinished_tasks += 1
        if self._cond.ready():
            self._cond.reset()

    def task_done(self):
        """Indicate that a formerly enqueued task is complete. Used by queue consumer threads.
        For each :meth:`get <Queue.get>` used to fetch a task, a subsequent call to
        :meth:`task_done` tells the queue
        that the processing on the task is complete.

        If a :meth:`join` is currently blocking, it will resume when all items have been processed
        (meaning that a :meth:`task_done` call was received for every item that had been
        :meth:`put <Queue.put>` into the queue).

        Raises a :exc:`ValueError` if called more times than there were items placed in the queue.
        """

        if self.unfinished_tasks <= 0:
            raise ValueError('task_done() called too many times')
        self.unfinished_tasks -= 1
        if self.unfinished_tasks == 0:
            self._cond.send(None)

    def join(self):
        """Block until all items in the queue have been gotten and processed

        The count of unfinished tasks goes up whenever an item is added to the queue.
        The count goes down whenever a consumer thread calls :meth:`task_done` to indicate
        that the item was retrieved and all work on it is complete. When the count of
        unfinished tasks drops to zero, :meth:`join` unblocks.
        """
        if self.unfinished_tasks > 0:
            self._cond.wait()
예제 #4
0
파일: queue.py 프로젝트: dmdm/guv
class Queue(LightQueue):
    """Create a queue object with a given maximum size

    If `maxsize` is less than zero or ``None``, the queue size is infinite.

    ``Queue(0)`` is a channel, that is, its :meth:`put` method always blocks until the item is
    delivered. (This is unlike the standard :class:`queue.Queue`, where 0 means infinite size).

    In all other respects, this Queue class resembles the standard library, :class:`queue.Queue`.
    """

    def __init__(self, maxsize=None):
        LightQueue.__init__(self, maxsize)
        self.unfinished_tasks = 0
        self._cond = Event()

    def _format(self):
        result = LightQueue._format(self)
        if self.unfinished_tasks:
            result += ' tasks=%s _cond=%s' % (self.unfinished_tasks, self._cond)
        return result

    def _put(self, item):
        LightQueue._put(self, item)
        self._put_bookkeeping()

    def _put_bookkeeping(self):
        self.unfinished_tasks += 1
        if self._cond.ready():
            self._cond.reset()

    def task_done(self):
        """Indicate that a formerly enqueued task is complete. Used by queue consumer threads.
        For each :meth:`get <Queue.get>` used to fetch a task, a subsequent call to
        :meth:`task_done` tells the queue
        that the processing on the task is complete.

        If a :meth:`join` is currently blocking, it will resume when all items have been processed
        (meaning that a :meth:`task_done` call was received for every item that had been
        :meth:`put <Queue.put>` into the queue).

        Raises a :exc:`ValueError` if called more times than there were items placed in the queue.
        """

        if self.unfinished_tasks <= 0:
            raise ValueError('task_done() called too many times')
        self.unfinished_tasks -= 1
        if self.unfinished_tasks == 0:
            self._cond.send(None)

    def join(self):
        """Block until all items in the queue have been gotten and processed

        The count of unfinished tasks goes up whenever an item is added to the queue.
        The count goes down whenever a consumer thread calls :meth:`task_done` to indicate
        that the item was retrieved and all work on it is complete. When the count of
        unfinished tasks drops to zero, :meth:`join` unblocks.
        """
        if self.unfinished_tasks > 0:
            self._cond.wait()
예제 #5
0
파일: queue.py 프로젝트: PlumpMath/guv
 def __init__(self, maxsize=None):
     LightQueue.__init__(self, maxsize)
     self.unfinished_tasks = 0
     self._cond = Event()
예제 #6
0
파일: queue.py 프로젝트: dmdm/guv
 def __init__(self, maxsize=None):
     LightQueue.__init__(self, maxsize)
     self.unfinished_tasks = 0
     self._cond = Event()