當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。