A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2008-December/083834.html below:

[Python-Dev] [Python-checkins] r67511 - in python/trunk: Doc/library/logging.rst Lib/logging/__init__.py Lib/test/test_logging.py Misc/NEWS

[Python-Dev] [Python-checkins] r67511 - in python/trunk: Doc/library/logging.rst Lib/logging/__init__.py Lib/test/test_logging.py Misc/NEWSNick Coghlan ncoghlan at gmail.com
Thu Dec 4 12:07:02 CET 2008
vinay.sajip wrote:
> +def _showwarning(message, category, filename, lineno, file=None, line=None):
> +    """
> +    Implementation of showwarnings which redirects to logging, which will first
> +    check to see if the file parameter is None. If a file is specified, it will
> +    delegate to the original warnings implementation of showwarning. Otherwise,
> +    it will call warnings.formatwarning and will log the resulting string to a
> +    warnings logger named "py.warnings" with level logging.WARNING.
> +    """
> +    if file is not None:
> +        if _warnings_showwarning is not None:
> +            _warnings_showwarning(message, category, filename, lineno, file, line)
> +    else:
> +        import warnings
> +        s = warnings.formatwarning(message, category, filename, lineno, line)
> +        logger = getLogger("py.warnings")
> +        if not logger.handlers:
> +            logger.addHandler(NullHandler())
> +        logger.warning("%s", s)

I'd be careful here - this could deadlock if a thread spawned as a side
effect of importing a module happens to trigger a warning.

warnings is pulled into sys.modules as part of the interpreter startup -
having a global "import warnings" shouldn't have any real effect on
logging's import time.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4