How to use the flower.core.bomb function in flower

To help you get started, we’ve selected a few flower 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 benoitc / flower / test / test_channel.py View on Github external
def test_bomb(self):
        try:
            1/0
        except:
            import sys
            b = core.bomb(*sys.exc_info())
        assert b.type is ZeroDivisionError
        if six.PY3:
            assert (str(b.value).startswith('division by zero') or
                    str(b.value).startswith('int division'))
        else:
            assert str(b.value).startswith('integer division')
        assert b.traceback is not None
github benoitc / flower / flower / net / sock.py View on Github external
def read(self):
        if self.closing:
            return ""

        while True:
            try:
                retval = self.queue.popleft()
                if self.cr.balance < 0:
                    self.cr.send(retval)

                if isinstance(retval, bomb):
                    retval.raise_()

                return retval
            except IndexError:
                pass

            msg = None
            buf = bytearray(DEFAULT_BUFFER_SIZE)
            try:
                recvd = recv_into(self.client, buf)
                msg =  bytes(buf[0:recvd])
            except socket.error:
                ex = sys.exc_info()[1]
                if ex.args[0] == EBADF:
                    msg = ""
                    self.closing = True
github benoitc / flower / flower / net / udp.py View on Github external
def on_recv(self, handler, addr, data, error):
        with self._lock:
            if addr in self.conns:
                conn = self.conns[addr]

                if error:
                    if error == 1:
                        msg = ""
                    else:
                        msg = bomb(IOError, IOError("uv error: %s" % error))
                else:
                    msg = data

                # emit last message
                conn.queue.append(msg)
                if conn.cr.balance < 0:
                    # someone is waiting, return last message
                    conn.cr.send(self.queue.popleft())

            elif len(self.listeners):
                listener = self.listeners.popleft()
                if error:
                    listener.c.send_exception(IOError, "uv error: %s" % error)
                else:
                    conn = UDPConn(addr)
                    conn.queue.append(data)
github benoitc / flower / flower / net / tcp.py View on Github external
def read(self):
        if not self.reading:
            self.reading = True
            self.client.start_read(self._on_read)

        self.client.loop.update_time()
        try:
            retval = self.queue.popleft()
            if self.cr.balance < 0:
                self.cr.send(retval)

            if isinstance(retval, bomb):
                retval.raise_()
            return retval
        except IndexError:
            pass

        return self.cr.receive()
github benoitc / flower / flower / net / sock.py View on Github external
def _read(self):
        buf = bytearray(DEFAULT_BUFFER_SIZE)
        try:
            recvd = recv_into(self.client, buf)
            msg =  bytes(buf[0:recvd])
        except socket.error:
            ex = sys.exc_info()[1]
            if ex.args[0] == EBADF:
                msg =  ""
            if ex.args[0] != EWOULDBLOCK or self.timeout == 0.0:
                msg = bomb(ex, sys.exc_info()[2])
            exc_clear()
        return msg
github benoitc / flower / flower / net / udp.py View on Github external
def read(self):
        try:
            retval = self.queue.popleft()
            if self.cr.balance < 0:
                self.cr.send(retval)

            if isinstance(retval, bomb):
                retval.raise_()
            return retval
        except IndexError:
            pass

        return self.cr.receive()
github benoitc / flower / flower / net / tcp.py View on Github external
def _on_read(self, handle, data, error):
        if error:
            if error == 1: # EOF
                msg = ""
            else:
                msg = bomb(IOError, IOError("uv error: %s" % error))
        else:
            msg = data

        # append the message to the queue
        self.queue.append(msg)

        if self.cr.balance < 0:
            # someone is waiting, return last message
            self.cr.send(self.queue.popleft())
github benoitc / flower / flower / net / sock.py View on Github external
return retval
            except IndexError:
                pass

            msg = None
            buf = bytearray(DEFAULT_BUFFER_SIZE)
            try:
                recvd = recv_into(self.client, buf)
                msg =  bytes(buf[0:recvd])
            except socket.error:
                ex = sys.exc_info()[1]
                if ex.args[0] == EBADF:
                    msg = ""
                    self.closing = True
                if ex.args[0] != EWOULDBLOCK or self.timeout == 0.0:
                    msg = bomb(ex, sys.exc_info()[2])
                    self.closing = True
                exc_clear()

            if msg is None:
                res = self._watch_read()
                if res is not None:
                    self.queue.append(res)

            else:
                self.queue.append(msg)
github benoitc / flower / flower / net / sock.py View on Github external
def _on_read(self, handle, events, error):
        if error and error is not None:
            self.readable = False
            if error == 1:
                self.closing = True
                msg = ""
            else:
                msg = bomb(IOError, IOError("uv error: %s" % error))
        else:
            self.readable = True
            msg = None
        self.cr.send(msg)