def func(a): try: log.f("ddd") raise exception.EPNoNodeError("def") except: print sys.exc_info() log.f("abc")
def _run_catch(self, func, path, path_is_dir=False): """ 执行func并捕获异常,将文件系统异常转换为对应的异常对象 """ ospath = self._base + path try: if os.path.exists(ospath): if path_is_dir: if os.path.isdir(ospath): return func() else: if os.path.isfile(ospath): # 判断文件是否过期,过期直接报错 mtime = os.stat(ospath).st_mtime if mtime < time.time() - self._timeout: self.delete_node(path, True) else: return func() else: return func() raise exception.EPNoNodeError() except exception.EPNoNodeError as e: log.r(e, "Node not exist:{}".format(path)) except Exception as e: log.r(exception.EPIOError(), "Request I/O Error")
def _run_catch(cls, func, path, path_is_dir=False): """ 执行func并捕获异常,将kazoo异常转换为对应的异常对象 """ try: if not os.path.exists(path) or (path_is_dir and not os.path.isdir(path)): raise exception.EPNoNodeError() return func() except exception.EPNoNodeError as e: log.r(e, "Node not exist:{}".format(path)) except: log.r(exception.EPIOError(), "Request I/O Error")
def _deletenode(path=np): # 由于redis不支持事务,所以此处并不会区分节点是否存在,均直接set数据 children = self.get_children(path) for child_node in children: _deletenode("/".join([path, child_node])) node_path, node_name = self._split_node_name(path) ret = self._handle.evalsha(self._delete_lua_sha, 2, node_path, node_name) if ret == -1: raise exception.EPNoNodeError("delete node[%s] error:%s" % (path, "Node has child"))
def _run_catch(cls, func): """ 执行func并捕获异常,将kazoo异常转换为对应的异常对象 """ import kazoo try: return func() except kazoo.interfaces.IHandler.timeout_exception: raise exception.EPConnectTimeout() except kazoo.exceptions.NoNodeError: raise exception.EPNoNodeError() except: log.r(exception.EPIOError(), "Request I/O Error")
def _run_catch(cls, func): """ 执行func并捕获异常,将kazoo异常转换为对应的异常对象 """ import kazoo try: return func() except kazoo.exceptions.NoNodeError: raise exception.EPNoNodeError() except kazoo.exceptions.ZookeeperError: log.f("zk fail") raise exception.EPServerError() except Exception as e: log.r(exception.EPIOError(), "Requesst I/O Error")
def _createnode(np=path): node_path, node_name = self._split_node_name(np) errmsg = { -1: "Node has ttl or parents-node not exists", -2: "Node exists(in parents-node record)", -3: "Node exists" } if not self.exists(node_path) and node_path != "/": if makepath: self.create_node(node_path, makepath=True) else: raise exception.EPNoNodeError(node_path + " not exists") seq = 1 if sequence else 0 tm = long(time.time()) + self._timeout if ephemeral else 0 ret = self._handle.evalsha(self._new_lua_sha, 2, node_path, node_name, value, seq, tm) if ret < 0: raise exception.EPIOError("redis error when create[%s:%s]:%s" % (node_path, node_name, errmsg[ret])) if ephemeral: self._new_touch(ret) return ret