mirror of
https://github.com/python/cpython.git
synced 2025-11-26 21:33:10 +00:00
Took Nick Coghlan's advice about importing warnings globally in logging, to avoid the possibility of race conditions: "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."
This commit is contained in:
parent
97f49f4be7
commit
6831d6bc7f
2 changed files with 6 additions and 8 deletions
|
|
@ -31,7 +31,7 @@ __all__ = ['BASIC_FORMAT', 'BufferingFormatter', 'CRITICAL', 'DEBUG', 'ERROR',
|
||||||
'INFO', 'LogRecord', 'Logger', 'Manager', 'NOTSET', 'PlaceHolder',
|
'INFO', 'LogRecord', 'Logger', 'Manager', 'NOTSET', 'PlaceHolder',
|
||||||
'RootLogger', 'StreamHandler', 'WARN', 'WARNING']
|
'RootLogger', 'StreamHandler', 'WARN', 'WARNING']
|
||||||
|
|
||||||
import sys, os, types, time, string, cStringIO, traceback
|
import sys, os, types, time, string, cStringIO, traceback, warnings
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import codecs
|
import codecs
|
||||||
|
|
@ -1520,7 +1520,6 @@ def _showwarning(message, category, filename, lineno, file=None, line=None):
|
||||||
if _warnings_showwarning is not None:
|
if _warnings_showwarning is not None:
|
||||||
_warnings_showwarning(message, category, filename, lineno, file, line)
|
_warnings_showwarning(message, category, filename, lineno, file, line)
|
||||||
else:
|
else:
|
||||||
import warnings
|
|
||||||
s = warnings.formatwarning(message, category, filename, lineno, line)
|
s = warnings.formatwarning(message, category, filename, lineno, line)
|
||||||
logger = getLogger("py.warnings")
|
logger = getLogger("py.warnings")
|
||||||
if not logger.handlers:
|
if not logger.handlers:
|
||||||
|
|
@ -1533,7 +1532,6 @@ def captureWarnings(capture):
|
||||||
If capture is False, ensure that warnings are not redirected to logging
|
If capture is False, ensure that warnings are not redirected to logging
|
||||||
but to their original destinations.
|
but to their original destinations.
|
||||||
"""
|
"""
|
||||||
import warnings
|
|
||||||
global _warnings_showwarning
|
global _warnings_showwarning
|
||||||
if capture:
|
if capture:
|
||||||
if _warnings_showwarning is None:
|
if _warnings_showwarning is None:
|
||||||
|
|
|
||||||
10
Misc/NEWS
10
Misc/NEWS
|
|
@ -67,11 +67,11 @@ Library
|
||||||
support unusual filenames (such as those containing semi-colons) in
|
support unusual filenames (such as those containing semi-colons) in
|
||||||
Content-Disposition headers.
|
Content-Disposition headers.
|
||||||
|
|
||||||
- Issue #4384: Added integration with warnings module using captureWarnings().
|
- Issue #4384: Added logging integration with warnings module using
|
||||||
This change includes a NullHandler which does nothing; it will be of use to
|
captureWarnings(). This change includes a NullHandler which does nothing;
|
||||||
library developers who want to avoid the "No handlers could be found for
|
it will be of use to library developers who want to avoid the "No handlers
|
||||||
logger XXX" message which can appear if the library user doesn't configure
|
could be found for logger XXX" message which can appear if the library user
|
||||||
logging.
|
doesn't configure logging.
|
||||||
|
|
||||||
- Issue #3741: DISTUTILS_USE_SDK set causes msvc9compiler.py to raise an
|
- Issue #3741: DISTUTILS_USE_SDK set causes msvc9compiler.py to raise an
|
||||||
exception.
|
exception.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue