def qstat(qconn=None, delay=None):
    def compare_tubes(last, cur):
        _cur = cur.copy()
        for _k, _v in last.items():
            try:
                change = int(_cur[_k]) - int(_v)
                if change > 0:
                    change = "+%s" % change
                elif change == 0:
                    change = ""
                _cur[_k] = "%-5s %s" % (_cur[_k], change)
            except __HOLE__:
                pass
                # Not an number
        return _cur

    def compare_numbers(last, cur):
        _cur = cur
        change = int(_cur) - int(last)
        if change > -1:
            change = "+%s" % change
        _cur = "%s %s" % (_cur, change)
        return _cur

    if not qconn:
        qconn = _get_qconnection(QHOST, QPORT)
    tubes_stats_last = {}
    while True:
        LINE="%-24s %-10s %-10s %-10s %-10s %-10s"
        print LINE % ('tube', 'watching', 'buried', 'ready', 'delayed', 'reserved')
        tubes = qconn.tubes()
        tubes.sort()
        for tube in tubes:
            if tube:
                name = str(tube)
                tube_stats_cur = qconn.stats_tube(tube)
                if tubes_stats_last.get(name):
                    tube_stats = compare_tubes(tubes_stats_last[name], tube_stats_cur)
                else:
                    tube_stats = tube_stats_cur

                #tube_stats = qconn.stats_tube(tube)
                print LINE % (name,
                        tube_stats.get('current-watching'),
                        tube_stats.get('current-jobs-buried'),
                        tube_stats.get('current-jobs-ready'),
                        tube_stats.get('current-jobs-delayed'),
                        tube_stats.get('current-jobs-reserved'))
                tubes_stats_last[name] = tube_stats_cur
        if delay:
            time.sleep(delay)
        else:
            return None
dataset/ETHPy150Open chexov/queueit/beanstalkd/queueit/__init__.py/qstat