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


Python Messages.getValue方法代码示例

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


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

示例1: EventHandler

# 需要导入模块: from messages import Messages [as 别名]
# 或者: from messages.Messages import getValue [as 别名]
class EventHandler(object):
    def __init__(self):
        self.dict = OrderedDict()
        self.dict['a'] = False
        self.dict['b'] = False
        self.dict['c'] = False
        self.dict['d'] = False
        self.dict['e'] = False
        self.dict['f'] = False
        self.messages = Messages()
        
#     向服务器发送item
    def send(self):
        for key in self.dict:
            value = self.dict[key]
            if not value:
                self.item = key
                break
        if self.dict[key]:
            return
        host = self.messages.getValue("socket1", "host")
        port = int(self.messages.getValue("socket1", "port"))
        params = (("deliverItem", self.item), self.sendCallBack)
#         检查当前item在服务器的状态,7次
        Thread(target=TCPClient(host, port).send, args=params).start()
        self.check(self.item)
        
    def sendCallBack(self, params):
        if params[1]:
            print("Send", params[0], "成功")
        elif len(params) == 3:
            print("Send", params[0], "出现异常", params[2])
    
#     轮询检查服务器端item的还行状况,7次
    def check(self, item):
        totalTimes = 7
        times = 0
        while times < totalTimes:
            time.sleep(1)
            if self.dict[item]:
                return
            host = self.messages.getValue("socket2", "host")
            port = int(self.messages.getValue("socket2", "port"))
            params = (("checkItemStatus", item), self.checkCallBack)
            Thread(target=TCPClient(host, port).send, args=params).start()
            times += 1
        else:
            print("已经对", item, "发起", totalTimes, "次校验,没有结果. 任务终止.")
        
    def checkCallBack(self, params):
        if params[1]:
            self.dict[params[0]] = params[1]
            print("Check", params[0], "成功。当前队列状态为:", self.dict.items())
            self.send()
        elif len(params) == 3:
            print("Check", params[0], "出现异常:", params[2])
        else:
            print("Check", params[0], "未得到结果")
开发者ID:weijingwei,项目名称:py_sendAndCheck,代码行数:60,代码来源:eventHandler.py

示例2: EchoRequestHandler

# 需要导入模块: from messages import Messages [as 别名]
# 或者: from messages.Messages import getValue [as 别名]
from pickle import loads, dumps
from socketserver import BaseRequestHandler, ThreadingTCPServer
from threading import Thread


class EchoRequestHandler(BaseRequestHandler):
    def handle(self):
        from utils import Utils
        print("Got new connection!")
        while True:
            msg = self.request.recv(1024)
            if not msg:
                break
            msg = loads(msg)
            print("Received:", msg)
            result = getattr(Utils(), msg[0])(msg[1])
            print(result)
            self.request.send(dumps(result))
            print("Done with connection")
    
if __name__ == '__main__':
    from messages import Messages
    messages = Messages()
    server1 = ThreadingTCPServer((messages.getValue("socket1", "host"), int(messages.getValue("socket1", "port"))), EchoRequestHandler)
    server2 = ThreadingTCPServer((messages.getValue("socket2", "host"), int(messages.getValue("socket2", "port"))), EchoRequestHandler)
    print("server running...")
    Thread(target=server1.serve_forever).start()
    Thread(target=server2.serve_forever).start()
开发者ID:weijingwei,项目名称:py_sendAndCheck,代码行数:30,代码来源:server.py


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