Python warnings.warning() Examples

The following are 6 code examples for showing how to use warnings.warning(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module warnings , or try the search function .

Example 1
Project: seismic-deeplearning   Author: microsoft   File: data.py    License: MIT License 6 votes vote down vote up
def _limit_inlines(max_inlines, images_iter):
    if max_inlines is not None:
        images_list = list(images_iter)
        if max_inlines > len(images_list):
            warn_msg = (
                f"The number of max inlines {max_inlines} is greater"
                f"than the number of inlines found {len(images_list)}."
                f"Setting max inlines to {len(images_list)}"
            )
            warnings.warning(warn_msg)
            max_inlines = len(images_list)
            images_iter = images_list
        else:
            shuffled_list = random.shuffle(images_list)
            images_iter = take(max_inlines, shuffled_list)
    return images_iter, max_inlines 
Example 2
Project: lkpy   Author: lenskit   File: __init__.py    License: MIT License 6 votes vote down vote up
def transfer(self):
        """
        Mark an object for ownership transfer.  This object, when pickled, will
        unpickle into an owning model that frees resources when closed. Used to
        transfer ownership of shared memory resources from child processes to
        parent processes.  Such an object should only be unpickled once.

        The default implementation sets the ``is_owner`` attribute to ``'transfer'``.

        Returns:
            ``self`` (for convenience)
        """
        if not self.is_owner:
            warnings.warning('non-owning objects should not be transferred', stacklevel=1)
        else:
            self.is_owner = 'transfer'
        return self 
Example 3
Project: incremental_learning.pytorch   Author: arthurdouillard   File: schedulers.py    License: MIT License 6 votes vote down vote up
def __init__(
        self, optimizer, t_max: int, eta_min: float = 0., last_epoch: int = -1, factor: float = 1.
    ) -> None:
        assert t_max > 0
        assert eta_min >= 0
        if t_max == 1 and factor == 1:
            warnings.warning(
                "Cosine annealing scheduler will have no effect on the learning "
                "rate since T_max = 1 and factor = 1."
            )
        self.t_max = t_max
        self.eta_min = eta_min
        self.factor = factor
        self._last_restart: int = 0
        self._cycle_counter: int = 0
        self._cycle_factor: float = 1.
        self._updated_cycle_len: int = t_max
        self._initialized: bool = False
        super(CosineWithRestarts, self).__init__(optimizer, last_epoch) 
Example 4
Project: cheroot   Author: cherrypy   File: threadpool.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def stop(self, timeout=5):
        """Terminate all worker threads.

        Args:
            timeout (int): time to wait for threads to stop gracefully
        """
        # for compatability, negative timeouts are treated like None
        # TODO: treat negative timeouts like already expired timeouts
        if timeout is not None and timeout < 0:
            timeout = None
            warnings.warning(
                'In the future, negative timeouts to Server.stop() '
                'will be equivalent to a timeout of zero.',
                stacklevel=2,
            )

        if timeout is not None:
            endtime = time.time() + timeout

        # Must shut down threads here so the code that calls
        # this method can know when all threads are stopped.
        for worker in self._threads:
            self._queue.put(_SHUTDOWNREQUEST)

        ignored_errors = (
            # TODO: explain this exception.
            AssertionError,
            # Ignore repeated Ctrl-C. See cherrypy#691.
            KeyboardInterrupt,
        )

        for worker in self._clear_threads():
            remaining_time = timeout and endtime - time.time()
            try:
                worker.join(remaining_time)
                if worker.is_alive():
                    # Timeout exhausted; forcibly shut down the socket.
                    self._force_close(worker.conn)
                    worker.join()
            except ignored_errors:
                pass 
Example 5
Project: Tautulli   Author: Tautulli   File: threadpool.py    License: GNU General Public License v3.0 5 votes vote down vote up
def stop(self, timeout=5):
        """Terminate all worker threads.

        Args:
            timeout (int): time to wait for threads to stop gracefully
        """
        # for compatability, negative timeouts are treated like None
        # TODO: treat negative timeouts like already expired timeouts
        if timeout is not None and timeout < 0:
            timeout = None
            warnings.warning(
                'In the future, negative timeouts to Server.stop() '
                'will be equivalent to a timeout of zero.',
                stacklevel=2,
            )

        if timeout is not None:
            endtime = time.time() + timeout

        # Must shut down threads here so the code that calls
        # this method can know when all threads are stopped.
        for worker in self._threads:
            self._queue.put(_SHUTDOWNREQUEST)

        ignored_errors = (
            # TODO: explain this exception.
            AssertionError,
            # Ignore repeated Ctrl-C. See cherrypy#691.
            KeyboardInterrupt,
        )

        for worker in self._clear_threads():
            remaining_time = timeout and endtime - time.time()
            try:
                worker.join(remaining_time)
                if worker.is_alive():
                    # Timeout exhausted; forcibly shut down the socket.
                    self._force_close(worker.conn)
                    worker.join()
            except ignored_errors:
                pass 
Example 6
Project: PsyNeuLink   Author: PrincetonUniversity   File: episodicmemorymechanism.py    License: Apache License 2.0 5 votes vote down vote up
def memory(self):
        """Return function's memory attribute"""
        try:
            return self.function.memory
        except:
            warnings.warning(f'Function of {self.name} (self.function.name) has no memory attribute')