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 ---------------------------------------------------------------
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