当前位置: 首页>>代码示例>>Python>>正文


Python AddrPool.free方法代码示例

本文整理汇总了Python中pyroute2.common.AddrPool.free方法的典型用法代码示例。如果您正苦于以下问题:Python AddrPool.free方法的具体用法?Python AddrPool.free怎么用?Python AddrPool.free使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyroute2.common.AddrPool的用法示例。


在下文中一共展示了AddrPool.free方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_free_reverse_fail

# 需要导入模块: from pyroute2.common import AddrPool [as 别名]
# 或者: from pyroute2.common.AddrPool import free [as 别名]
    def test_free_reverse_fail(self):

        ap = AddrPool(minaddr=1, maxaddr=1024, reverse=True)
        try:
            ap.free(0)
        except KeyError:
            pass
开发者ID:0x90,项目名称:pyroute2,代码行数:9,代码来源:test_addrpool.py

示例2: test_setaddr_allocated

# 需要导入模块: from pyroute2.common import AddrPool [as 别名]
# 或者: from pyroute2.common.AddrPool import free [as 别名]
    def test_setaddr_allocated(self):

        ap = AddrPool()
        f = ap.alloc()
        base, bit, is_allocated = ap.locate(f + 1)
        assert not is_allocated
        assert ap.allocated == 1
        ap.setaddr(f + 1, 'allocated')
        base, bit, is_allocated = ap.locate(f + 1)
        assert is_allocated
        assert ap.allocated == 2
        ap.free(f + 1)
        base, bit, is_allocated = ap.locate(f + 1)
        assert not is_allocated
        assert ap.allocated == 1
开发者ID:nazarewk,项目名称:pyroute2,代码行数:17,代码来源:test_addrpool.py

示例3: test_setaddr_free

# 需要导入模块: from pyroute2.common import AddrPool [as 别名]
# 或者: from pyroute2.common.AddrPool import free [as 别名]
    def test_setaddr_free(self):

        ap = AddrPool()
        f = ap.alloc()
        base, bit, is_allocated = ap.locate(f + 1)
        assert not is_allocated
        assert ap.allocated == 1
        ap.setaddr(f + 1, 'free')
        base, bit, is_allocated = ap.locate(f + 1)
        assert not is_allocated
        assert ap.allocated == 1
        ap.setaddr(f, 'free')
        base, bit, is_allocated = ap.locate(f)
        assert not is_allocated
        assert ap.allocated == 0
        try:
            ap.free(f)
        except KeyError:
            pass
开发者ID:nazarewk,项目名称:pyroute2,代码行数:21,代码来源:test_addrpool.py

示例4: NetlinkMixin

# 需要导入模块: from pyroute2.common import AddrPool [as 别名]
# 或者: from pyroute2.common.AddrPool import free [as 别名]

#.........这里部分代码省略.........
                        # for every turn separately
                        ctime = time.time()
                        #
                        current = self.buffer_queue.qsize()
                        delta = current - self.qsize
                        if delta > 10:
                            delay = min(3, max(0.01, float(current) / 60000))
                            message = ("Packet burst: the reader thread "
                                       "priority is increased, beware of "
                                       "delays on netlink calls\n\tCounters: "
                                       "delta=%s qsize=%s delay=%s "
                                       % (delta, current, delay))
                            if delay < 1:
                                log.debug(message)
                            else:
                                log.warning(message)
                            time.sleep(delay)
                        self.qsize = current

                        # We've got the data, lock the backlog again
                        self.backlog_lock.acquire()
                        for msg in msgs:
                            seq = msg['header']['sequence_number']
                            if seq not in self.backlog:
                                if msg['header']['type'] == NLMSG_ERROR:
                                    # Drop orphaned NLMSG_ERROR messages
                                    continue
                                seq = 0
                            # 8<-----------------------------------------------
                            # Callbacks section
                            for cr in self.callbacks:
                                try:
                                    if cr[0](msg):
                                        cr[1](msg, *cr[2])
                                except:
                                    log.warning("Callback fail: %s" % (cr))
                                    log.warning(traceback.format_exc())
                            # 8<-----------------------------------------------
                            self.backlog[seq].append(msg)
                        # We finished with the backlog, so release the lock
                        self.backlog_lock.release()

                        # Now wake up other threads
                        self.change_master.set()

                        # Finally, release the read lock: all data processed
                        self.read_lock.release()
                    else:
                        # If the socket is occupied and there is still no
                        # data for us, wait for the next master change or
                        # for a timeout
                        self.change_master.wait(1)
                    # 8<-------------------------------------------------------
                    #
                    # Stage 2. END
                    #
                    # 8<-------------------------------------------------------

            return ret

    def nlm_request(self, msg, msg_type,
                    msg_flags=NLM_F_REQUEST | NLM_F_DUMP,
                    terminate=None,
                    exception_catch=Exception,
                    exception_handler=None):

        def do_try():
            msg_seq = self.addr_pool.alloc()
            with self.lock[msg_seq]:
                try:
                    msg.reset()
                    self.put(msg, msg_type, msg_flags, msg_seq=msg_seq)
                    ret = self.get(msg_seq=msg_seq, terminate=terminate)
                    return ret
                except Exception:
                    raise
                finally:
                    # Ban this msg_seq for 0xff rounds
                    #
                    # It's a long story. Modern kernels for RTM_SET.*
                    # operations always return NLMSG_ERROR(0) == success,
                    # even not setting NLM_F_MULTY flag on other response
                    # messages and thus w/o any NLMSG_DONE. So, how to detect
                    # the response end? One can not rely on NLMSG_ERROR on
                    # old kernels, but we have to support them too. Ty, we
                    # just ban msg_seq for several rounds, and NLMSG_ERROR,
                    # being received, will become orphaned and just dropped.
                    #
                    # Hack, but true.
                    self.addr_pool.free(msg_seq, ban=0xff)

        while True:
            try:
                return do_try()
            except exception_catch as e:
                if exception_handler and not exception_handler(e):
                    continue
                raise
            except Exception:
                raise
开发者ID:kinhvan017,项目名称:pyroute2,代码行数:104,代码来源:nlsocket.py

示例5: test_free

# 需要导入模块: from pyroute2.common import AddrPool [as 别名]
# 或者: from pyroute2.common.AddrPool import free [as 别名]
    def test_free(self):

        ap = AddrPool(minaddr=1, maxaddr=1024)
        f = ap.alloc()
        ap.free(f)
开发者ID:0x90,项目名称:pyroute2,代码行数:7,代码来源:test_addrpool.py


注:本文中的pyroute2.common.AddrPool.free方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。