def add_cells_by_cfg(self, frames): """ 根据cfg配置情况,启动子进程 cfg: [{name:'name', cls: '', funcs:['func1', 'func2', ...], kw:{}}, ] name: 名称 mode: 子进程运行模式, single=单一子进程, multi=负载均衡子进程 funcs: 子进程函数列表 kw: 子进程类创建参数字典 """ for values in frames: name = values['name'] funcs = values['funcs'] cls_name = values.get('mode', '') kw = values.get('kw', {}) #指定地址 addr = values.get('addr', None) if addr: self.reg_sub_proxy_addr(name, addr) if not cls_name or cls_name == 'single': cls = SingleCell elif cls_name == 'multi': cls = MultiCell else: cls = common.import1(cls_name) cell = cls(self, name, funcs, **kw) self.add_cell(cell)
def main(): if '-h' in sys.argv: print u""" 游戏模拟,格式: python main.py client <script_name> arg1 arg2 arg3 ... 举例: python main.py client main 127.0.0.1 8002 """.decode('utf-8').encode(encoding) sys.exit(0) #处理压缩、解压问题 #client_rpc.JsonPacker.ZIP, client_rpc.JsonUnPacker.UNZIP = 1, 1 #处理压缩、解压问题 #client_rpc.JsonPacker.ZIP, client_rpc.JsonUnPacker.UNZIP = 1, 1 if '-w' in sys.argv: test = Web() test.run() from corelib import log log.console_config(True) log.debug(sys.argv) index = 1 script_name = sys.argv[index] args = sys.argv[index + 1:] md = 'client.scripts.%s' % script_name script = import1(md) script(*args)
def register(self, obj_func): """ 注册对象 """ if isinstance(obj_func, str): objs = common.import1(obj_func)() else: objs = obj_func() names = self.reg_objs(objs) return names
def test(host, port, test_name, name='test_main', pwd='test_main'): UDID = name DT = name addr = (host, int(port)) user = login_user(addr, name, pwd, UDID, DT) player = enter_player(user, name) md = 'client.scripts.%s' % test_name script = import1(md) script(player)
def __init__(self, *args, **kw): """ @param: check: 检查函数或字符串(def check(cell): return 0|1|-1), 检查函数返回: 0=不处理, -1=减少, 1=增加 """ self._check_func = kw.pop('check') if isinstance(self._check_func, str): self._check_func = common.import1(self._check_func) BaseCell.__init__(self, *args, **kw) self.sub_proxys = [] self.index = 0