當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。