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


Python exceptions.RuntimeError方法代码示例

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


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

示例1: update_version

# 需要导入模块: import exceptions [as 别名]
# 或者: from exceptions import RuntimeError [as 别名]
def update_version(self):
        """
            @return: updated VersionsFile
        """
        fw_gr, versions_file, new_tags = ua.github_repo_new(self._repo_framework,
                'silverstripe/framework', self.versions_file, self.update_majors)
        cms_gr, _, _ = ua.github_repo_new(self._repo_cms,
                'silverstripe/cms', self.versions_file, self.update_majors)

        hashes = {}
        for version in new_tags:
            fw_gr.tag_checkout(version)
            try:
                cms_gr.tag_checkout(version)
            except exceptions.RuntimeError:
                print("Version %s does not exist on `cms` branch. Skipping.")
                continue

            hashes[version] = ua.hashes_get(versions_file, './.update-workspace/silverstripe/')

        versions_file.update(hashes)
        return versions_file 
开发者ID:droope,项目名称:droopescan,代码行数:24,代码来源:silverstripe.py

示例2: some_function

# 需要导入模块: import exceptions [as 别名]
# 或者: from exceptions import RuntimeError [as 别名]
def some_function():
    """A function."""
    exc = None

    try:
        {}["a"]
    except KeyError, exceptions.RuntimeError: # [redefine-in-handler]
        pass 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:10,代码来源:redefine_in_handler.py

示例3: sg

# 需要导入模块: import exceptions [as 别名]
# 或者: from exceptions import RuntimeError [as 别名]
def sg(sampler):
    """returns the spectral gap
    t: transition matrix
    """
    while True:
        try:
            t = sampler.get_empirical_transition_matrix()
            w,v = eig(t)
            w_ord = np.sort(w)[::-1]
            if np.around(np.real_if_close(w_ord[0]), decimals=5) != 1:
                raise Exception("no eval with value 1")
            return 1 - np.absolute(w_ord[1])
        except RuntimeError:
            sampler.sample(1000) 
开发者ID:rueberger,项目名称:MJHMC,代码行数:16,代码来源:mixing.py

示例4: ip_numeric

# 需要导入模块: import exceptions [as 别名]
# 或者: from exceptions import RuntimeError [as 别名]
def ip_numeric(ip, ip_mode):
        """Returns numerical value from IP address."""
        if ip_mode == socket.AF_INET:
            # Returns numerical value from IPv4 address (dotted string).
            return struct.unpack('!I', socket.inet_pton(socket.AF_INET, ip))[0]
        elif ip_mode == socket.AF_INET6:
            return int(binascii.hexlify(socket.inet_pton(socket.AF_INET6, ip)),
                       16)
        else:
            raise exceptions.RuntimeError('Invalid IP mode %s' % ip_mode) 
开发者ID:google,项目名称:transperf,代码行数:12,代码来源:virtsetup.py

示例5: numeric_ip

# 需要导入模块: import exceptions [as 别名]
# 或者: from exceptions import RuntimeError [as 别名]
def numeric_ip(numeric, ip_mode):
        """Returns IP address from numerical value."""
        if ip_mode == socket.AF_INET:
            # Returns IPv4 address (dotted string) from numerical value.
            return socket.inet_ntop(socket.AF_INET, struct.pack('!I', numeric))
        elif ip_mode == socket.AF_INET6:
            # pad=32 is to 0-pad all 128 bits.
            hex_form = '{value:0{pad}x}'.format(value=numeric, pad=32)
            return socket.inet_ntop(socket.AF_INET6,
                                    binascii.unhexlify(hex_form))
        else:
            raise exceptions.RuntimeError('Invalid IP mode %s' % ip_mode) 
开发者ID:google,项目名称:transperf,代码行数:14,代码来源:virtsetup.py

示例6: verify_iface_cfg

# 需要导入模块: import exceptions [as 别名]
# 或者: from exceptions import RuntimeError [as 别名]
def verify_iface_cfg(iface_cfg, ip_mode):
        """Verifies interface exists with configured address."""
        iface = iface_cfg['name']
        cmd = 'ip addr show dev {iface}'.format(iface=iface)
        out, err, _ = Utils.run(cmd)
        lines = out.splitlines()
        errlines = err.splitlines()
        # Verify iface exists.
        assert lines, 'No output for %s' % cmd
        assert (not errlines or
                'does not exist' not in errlines[0]), ('Device %s '
                                                       'does not exist.' %
                                                       iface)
        # Verify address.
        matcher = 'inet6' if ip_mode == socket.AF_INET6 else 'inet'
        for line in lines:
            splits = line.split()
            if not splits:
                continue
            if splits[0] != matcher:
                continue
            addr = splits[1]
            if addr == iface_cfg['address'][ip_mode]:
                return
        error = 'Unable to verify interface: %s' % iface_cfg
        LOG.error(error)
        raise RuntimeError(error) 
开发者ID:google,项目名称:transperf,代码行数:29,代码来源:virtsetup.py

示例7: setup_container_environment

# 需要导入模块: import exceptions [as 别名]
# 或者: from exceptions import RuntimeError [as 别名]
def setup_container_environment(self):
        """Setup container environment for experiment.

        Performs the following actions:
        1. Delete existing node containers and bridge device, as well as all
           interfaces connected to bridge device. Unmounts /etc/hosts if needed.
           (We temporarily bind mount per transperf run for node addresses).
        2. Creates virtual bridge and rootns veth pair for contacting nodes in
           namespace (ROOT_TRANSPERF_ADDR/TRANSPERF_SUBNET) with stp off.
        3. Remounts (--make-private, --bind) mount namespace dir.
        4. Creates a container per node with these persistent namespaces:
           uts: <outdir>/uts/<container>
           mount: <outdir>/mntns/<container>
           netns: /var/run/netns/<container>
           with a running 'screen' session as the initial process.
           Creates per-node directories and performs necessary mount ops.

        NB: This method does *not* connect the containers to the bridge
        (see: container.setup_all_container_interfaces() instead).
        It also does not create a custom /etc/hosts file (only orch.py can do
        that since it can vary from config file to config file).
        It also does not handle custom /etc/hosts file bind-mounting
        (see: initialization code in recv.py/send.py/orch.py instead).

        Raises:
            RuntimeError if an operation fails during container setup.

        """
        # Ensures bonding module is loaded.
        IfUtils.ensure_bonding_available()

        # Delete existing bridge.
        IfUtils.delete_bridge(self.brdev)

        # Prepare to create namespaces.
        self.__prepare_ns_dirs()

        # Cleanup existing nodes as necessary.
        for node in self.nodes:
            net_ns = node
            cmd = 'ip netns del {ns}'.format(ns=net_ns)
            Utils.run(cmd)
            # NB: We do not clean up the node processes, however.

        # Create bridge.
        IfUtils.create_bridge(self.brdev)
        assert IfUtils.br_exists(self.brdev), ('Cannot create '
                                               'bridge %s' % self.brdev)

        # Create root veth pair and attach to bridge.
        IfUtils.setup_root_veth(self.brdev, self.ip_mode)
        IfUtils.verify_iface_cfg(Constants.ROOT_TRANSPERF_IFACE, self.ip_mode)
        IfUtils.verify_iface_on_br(self.brdev,
                                   Constants.ROOT_TRANSPERF_IFACE['br-pair'])

        # Create node containers.
        for node in self.nodes:
            self.__create_node_container(node) 
开发者ID:google,项目名称:transperf,代码行数:60,代码来源:virtsetup.py

示例8: setup_all_container_interfaces

# 需要导入模块: import exceptions [as 别名]
# 或者: from exceptions import RuntimeError [as 别名]
def setup_all_container_interfaces(self, node_cfg_dict):
        """Assigns addresses and creates interfaces for all nodes.

        Performs the following actions:
        1. For each node, assign an address, >= 1 + ROOT_TRANSPERF_ADDR.
        2. For each node, setup the container interfaces with the assigned
           address.

        Args:
            node_cfg_dict: A per-node configuration for interfaces.

        Return:
            Nothing.

        Raises:
            RuntimeError: if an operation fails.
        """
        base = Utils.ip_numeric(Constants.ROOT_TRANSPERF_ADDR[self.ip_mode],
                                self.ip_mode)
        nextval = base + 1
        mask = Constants.TRANSPERF_SUBNET[self.ip_mode]
        node_dns = []

        # Check if we have too many nodes.
        max_nodes = Constants.MAX_NODES[self.ip_mode]
        if len(self.nodes) >= max_nodes:
            raise RuntimeError('Too many nodes (%d given, max %d)' %
                               (len(self.nodes), max_nodes))

        # IFB device module is not virtualized by netns. Need to setup IFBs in
        # root namespace and move into the per-node namespaces.
        self.__setup_node_ifbs(node_cfg_dict)

        # Assign subsequent nodes the next available IP address.
        for node in self.nodes:
            val = nextval
            nextval += 1
            node_addr = '{ip}/{mask}'.format(ip=Utils.numeric_ip(val,
                                                                 self.ip_mode),
                                             mask=mask)
            # Get per-node cfg and setup interfaces for node.
            node_cfg = self.__get_node_cfg(node, node_cfg_dict)
            self.__setup_container_interfaces(node, node_addr, node_cfg)
            # DNS entry for augmented /etc/hosts file.
            dns = '{addr} {node}'.format(addr=node_addr.split('/')[0],
                                         node=node)
            node_dns.append(dns)

        # Add nodes to hosts file and bind-mount it on top of regular file.
        new_hosts = os.path.join(self.out_dir, 'hosts')
        with open(new_hosts, 'w') as new_file:
            for dns in node_dns:
                new_file.write('%s\n' % dns)
            new_file.close() 
开发者ID:google,项目名称:transperf,代码行数:56,代码来源:virtsetup.py


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