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


Python Bank.activate_cdkey方法代码示例

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


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

示例1: BankNode

# 需要导入模块: from bank import Bank [as 别名]
# 或者: from bank.Bank import activate_cdkey [as 别名]
class BankNode(node.Node):
    def __init__(self, nickname, port):
        # over
        super(BankNode, self).__init__(nickname,port,'bank')
        thread.start_new_thread(self.node_main, ())
        self.bank = Bank()
        self.cl_list = []
        self.addr_list = []
        self.mylock = threading.RLock()

    # method to activate the cdKey as the node requests
    def onActivate(self, socket, addr, node, msg):
        # activate the cdkey
        self.mylock.acquire()
        result = self.bank.activate_cdkey(msg['cdkey'])
        # sleep for concurrent test
        # time.sleep(5)
        # if it is num
        if not self.is_num(result):
            socket.send(self.msg.answerActivate(balance=result))
        # if it is not num, then error.
        else:
            socket.send(self.msg.answerActivate(info=result))
        logging.info('%s'%result)
        self.mylock.release()

    # re-write the listen method maintaining queue for waiting
    def listen(self):
        while True:
            logging.info('Listening...')
            try:
                logging.info(self)
                client, addr = self._server.accept()
                logging.info('connection from: %s:%d' % (addr[0], addr[1]))
                self.cl_list.append(client)
                self.addr_list.append(addr)
            except KeyboardInterrupt:
                break

    # new method to handle the listener in queue by order
    def node_main(self):
        while True:
            if self.cl_list and self.addr_list:
                self.handle_client(self.cl_list[0], self.addr_list[0])
                del(self.cl_list[0])
                del (self.addr_list[0])
    # Not Num : True; Num: False
    def is_num(self, argv):
        for i in range(len(argv)):
            if not '0' <= argv[i] <= '9':
                return True
        return False
开发者ID:BryanCui,项目名称:Distributed_Algorithms_Project,代码行数:54,代码来源:commonwealth.py


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