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


Python warnings.warn方法代码示例

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


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

示例1: check_app_config_entries_dont_start_with_script_name

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import warn [as 别名]
def check_app_config_entries_dont_start_with_script_name(self):
        """Check for App config with sections that repeat script_name."""
        for sn, app in cherrypy.tree.apps.items():
            if not isinstance(app, cherrypy.Application):
                continue
            if not app.config:
                continue
            if sn == '':
                continue
            sn_atoms = sn.strip('/').split('/')
            for key in app.config.keys():
                key_atoms = key.strip('/').split('/')
                if key_atoms[:len(sn_atoms)] == sn_atoms:
                    warnings.warn(
                        'The application mounted at %r has config '
                        'entries that start with its script name: %r' % (sn,
                                                                         key)) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:19,代码来源:_cpchecker.py

示例2: check_site_config_entries_in_app_config

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import warn [as 别名]
def check_site_config_entries_in_app_config(self):
        """Check for mounted Applications that have site-scoped config."""
        for sn, app in cherrypy.tree.apps.items():
            if not isinstance(app, cherrypy.Application):
                continue

            msg = []
            for section, entries in app.config.items():
                if section.startswith('/'):
                    for key, value in entries.items():
                        for n in ('engine.', 'server.', 'tree.', 'checker.'):
                            if key.startswith(n):
                                msg.append('[%s] %s = %s' %
                                           (section, key, value))
            if msg:
                msg.insert(0,
                           'The application mounted at %r contains the '
                           'following config entries, which are only allowed '
                           'in site-wide config. Move them to a [global] '
                           'section and pass them to cherrypy.config.update() '
                           'instead of tree.mount().' % sn)
                warnings.warn(os.linesep.join(msg)) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:24,代码来源:_cpchecker.py

示例3: get_app

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import warn [as 别名]
def get_app(self, app=None):
        """Obtain a new (decorated) WSGI app to hook into the origin server."""
        if app is None:
            app = cherrypy.tree

        if self.validate:
            try:
                from wsgiref import validate
            except ImportError:
                warnings.warn(
                    'Error importing wsgiref. The validator will not run.')
            else:
                # wraps the app in the validator
                app = validate.validator(app)

        return app 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:18,代码来源:helper.py

示例4: pipe_fopen

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import warn [as 别名]
def pipe_fopen(command, mode, background=True):
    if mode not in ["rb", "r"]:
        raise RuntimeError("Now only support input from pipe")

    p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)

    def background_command_waiter(command, p):
        p.wait()
        if p.returncode != 0:
            warnings.warn("Command \"{0}\" exited with status {1}".format(
                command, p.returncode))
            _thread.interrupt_main()

    if background:
        thread = threading.Thread(target=background_command_waiter,
                                  args=(command, p))
        # exits abnormally if main thread is terminated .
        thread.daemon = True
        thread.start()
    else:
        background_command_waiter(command, p)
    return p.stdout 
开发者ID:funcwj,项目名称:kaldi-python-io,代码行数:24,代码来源:inst.py

示例5: fprop

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import warn [as 别名]
def fprop(self, x, y, **kwargs):
        if self.attack is not None:
            x = x, self.attack(x)
        else:
            x = x,

        # Catching RuntimeError: Variable -= value not supported by tf.eager.
        try:
            y -= self.smoothing * (y - 1. / tf.cast(y.shape[-1], tf.float32))
        except RuntimeError:
            y.assign_sub(self.smoothing * (y - 1. / tf.cast(y.shape[-1],
                                                            tf.float32)))

        logits = [self.model.get_logits(x, **kwargs) for x in x]
        loss = sum(
            softmax_cross_entropy_with_logits(labels=y,
                                              logits=logit)
            for logit in logits)
        warnings.warn("LossCrossEntropy is deprecated, switch to "
                      "CrossEntropy. LossCrossEntropy may be removed on "
                      "or after 2019-03-06.")
        return loss 
开发者ID:StephanZheng,项目名称:neural-fingerprinting,代码行数:24,代码来源:loss.py

示例6: to_categorical

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import warn [as 别名]
def to_categorical(y, num_classes=None):
    """
    Converts a class vector (integers) to binary class matrix.
    This is adapted from the Keras function with the same name.
    :param y: class vector to be converted into a matrix
              (integers from 0 to num_classes).
    :param num_classes: num_classes: total number of classes.
    :return: A binary matrix representation of the input.
    """
    y = np.array(y, dtype='int').ravel()
    if not num_classes:
        num_classes = np.max(y) + 1
        warnings.warn("FutureWarning: the default value of the second"
                      "argument in function \"to_categorical\" is deprecated."
                      "On 2018-9-19, the second argument"
                      "will become mandatory.")
    n = y.shape[0]
    categorical = np.zeros((n, num_classes))
    categorical[np.arange(n), y] = 1
    return categorical 
开发者ID:StephanZheng,项目名称:neural-fingerprinting,代码行数:22,代码来源:utils.py

示例7: _get_logits_name

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import warn [as 别名]
def _get_logits_name(self):
        """
        Looks for the name of the layer producing the logits.
        :return: name of layer producing the logits
        """
        softmax_name = self._get_softmax_name()
        softmax_layer = self.model.get_layer(softmax_name)

        if not isinstance(softmax_layer, Activation):
            # In this case, the activation is part of another layer
            return softmax_name

        if hasattr(softmax_layer, 'inbound_nodes'):
            warnings.warn(
                "Please update your version to keras >= 2.1.3; "
                "support for earlier keras versions will be dropped on "
                "2018-07-22")
            node = softmax_layer.inbound_nodes[0]
        else:
            node = softmax_layer._inbound_nodes[0]

        logits_name = node.inbound_layers[0].name

        return logits_name 
开发者ID:StephanZheng,项目名称:neural-fingerprinting,代码行数:26,代码来源:utils_keras.py

示例8: model_loss

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import warn [as 别名]
def model_loss(y, model, mean=True):
    """
    Define loss of TF graph
    :param y: correct labels
    :param model: output of the model
    :param mean: boolean indicating whether should return mean of loss
                 or vector of losses for each input of the batch
    :return: return mean of loss if True, otherwise return vector with per
             sample loss
    """
    warnings.warn('This function is deprecated.')
    op = model.op
    if op.type == "Softmax":
        logits, = op.inputs
    else:
        logits = model

    out = softmax_cross_entropy_with_logits(logits=logits, labels=y)

    if mean:
        out = reduce_mean(out)
    return out 
开发者ID:StephanZheng,项目名称:neural-fingerprinting,代码行数:24,代码来源:utils_tf.py

示例9: infer_devices

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import warn [as 别名]
def infer_devices(devices=None):
    """
    Returns the list of devices that multi-replica code should use.
    :param devices: list of string device names, e.g. ["/GPU:0"]
        If the user specifies this, `infer_devices` checks that it is
        valid, and then uses this user-specified list.
        If the user does not specify this, infer_devices uses:
            - All available GPUs, if there are any
            - CPU otherwise
    """
    if devices is None:
        devices = get_available_gpus()
        if len(devices) == 0:
            warnings.warn("No GPUS, running on CPU")
            # Set device to empy string, tf will figure out whether to use
            # XLA or not, etc., automatically
            devices = [""]
    else:
        assert len(devices) > 0
        for device in devices:
            assert isinstance(device, str), type(device)
    return devices 
开发者ID:StephanZheng,项目名称:neural-fingerprinting,代码行数:24,代码来源:utils_tf.py

示例10: enable_receiving

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import warn [as 别名]
def enable_receiving(self):
        """
        Switch the monitor into listing mode.

        Connect to the event source and receive incoming events.  Only after
        calling this method, the monitor listens for incoming events.

        .. note::

           This method is implicitly called by :meth:`__iter__`.  You don't
           need to call it explicitly, if you are iterating over the
           monitor.

        .. deprecated:: 0.16
           Will be removed in 1.0. Use :meth:`start()` instead.
        """
        import warnings
        warnings.warn('Will be removed in 1.0. Use Monitor.start() instead.',
                      DeprecationWarning)
        self.start() 
开发者ID:mbusb,项目名称:multibootusb,代码行数:22,代码来源:monitor.py

示例11: from_sys_path

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import warn [as 别名]
def from_sys_path(cls, context, sys_path): #pragma: no cover
        """
        .. versionchanged:: 0.4
           Raise :exc:`NoSuchDeviceError` instead of returning ``None``, if
           no device was found for ``sys_path``.
        .. versionchanged:: 0.5
           Raise :exc:`DeviceNotFoundAtPathError` instead of
           :exc:`NoSuchDeviceError`.
        .. deprecated:: 0.18
           Use :class:`Devices.from_sys_path` instead.
        """
        import warnings
        warnings.warn(
           'Will be removed in 1.0. Use equivalent Devices method instead.',
           DeprecationWarning,
           stacklevel=2
        )
        return Devices.from_sys_path(context, sys_path) 
开发者ID:mbusb,项目名称:multibootusb,代码行数:20,代码来源:_device.py

示例12: traverse

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import warn [as 别名]
def traverse(self):
        """
        Traverse all parent devices of this device from bottom to top.

        Return an iterable yielding all parent devices as :class:`Device`
        objects, *not* including the current device.  The last yielded
        :class:`Device` is the top of the device hierarchy.

        .. deprecated:: 0.16
           Will be removed in 1.0. Use :attr:`ancestors` instead.
        """
        import warnings
        warnings.warn(
           'Will be removed in 1.0. Use Device.ancestors instead.',
           DeprecationWarning,
           stacklevel=2
        )
        return self.ancestors 
开发者ID:mbusb,项目名称:multibootusb,代码行数:20,代码来源:_device.py

示例13: __iter__

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import warn [as 别名]
def __iter__(self):
        """
        Iterate over the names of all properties defined for this device.

        Return a generator yielding the names of all properties of this
        device as unicode strings.

        .. deprecated:: 0.21
           Will be removed in 1.0. Access properties with Device.properties.
        """
        import warnings
        warnings.warn(
           'Will be removed in 1.0. Access properties with Device.properties.',
           DeprecationWarning,
           stacklevel=2
        )
        return self.properties.__iter__() 
开发者ID:mbusb,项目名称:multibootusb,代码行数:19,代码来源:_device.py

示例14: __getitem__

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import warn [as 别名]
def __getitem__(self, prop):
        """
        Get the given property from this device.

        ``prop`` is a unicode or byte string containing the name of the
        property.

        Return the property value as unicode string, or raise a
        :exc:`~exceptions.KeyError`, if the given property is not defined
        for this device.

        .. deprecated:: 0.21
           Will be removed in 1.0. Access properties with Device.properties.
        """
        import warnings
        warnings.warn(
           'Will be removed in 1.0. Access properties with Device.properties.',
           DeprecationWarning,
           stacklevel=2
        )
        return self.properties.__getitem__(prop) 
开发者ID:mbusb,项目名称:multibootusb,代码行数:23,代码来源:_device.py

示例15: asint

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import warn [as 别名]
def asint(self, prop):
        """
        Get the given property from this device as integer.

        ``prop`` is a unicode or byte string containing the name of the
        property.

        Return the property value as integer. Raise a
        :exc:`~exceptions.KeyError`, if the given property is not defined
        for this device, or a :exc:`~exceptions.ValueError`, if the property
        value cannot be converted to an integer.

        .. deprecated:: 0.21
           Will be removed in 1.0. Use Device.properties.asint() instead.
        """
        import warnings
        warnings.warn(
           'Will be removed in 1.0. Use Device.properties.asint instead.',
           DeprecationWarning,
           stacklevel=2
        )
        return self.properties.asint(prop) 
开发者ID:mbusb,项目名称:multibootusb,代码行数:24,代码来源:_device.py


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