提交 e842fd19 authored 作者: Brandon T. Willard's avatar Brandon T. Willard

Update logger library usage

上级 a9e8c7c3
...@@ -33,21 +33,6 @@ import sys ...@@ -33,21 +33,6 @@ import sys
import warnings import warnings
def has_handlers(logger):
# copied from Logger.hasHandlers() (introduced in Python 3.2)
_logger = logger
_has_handler = False
while _logger:
if _logger.handlers:
_has_handler = True
break
if not _logger.propagate:
break
else:
_logger = _logger.parent
return _has_handler
theano_logger = logging.getLogger("theano") theano_logger = logging.getLogger("theano")
logging_default_handler = logging.StreamHandler() logging_default_handler = logging.StreamHandler()
logging_default_formatter = logging.Formatter( logging_default_formatter = logging.Formatter(
...@@ -56,40 +41,27 @@ logging_default_formatter = logging.Formatter( ...@@ -56,40 +41,27 @@ logging_default_formatter = logging.Formatter(
logging_default_handler.setFormatter(logging_default_formatter) logging_default_handler.setFormatter(logging_default_formatter)
theano_logger.setLevel(logging.WARNING) theano_logger.setLevel(logging.WARNING)
if has_handlers(theano_logger) is False: if not theano_logger.hasHandlers():
theano_logger.addHandler(logging_default_handler) theano_logger.addHandler(logging_default_handler)
# Disable default log handler added to theano_logger when the module # Disable default log handler added to theano_logger when the module
# is imported. # is imported.
def disable_log_handler(logger=theano_logger, handler=logging_default_handler): def disable_log_handler(logger=theano_logger, handler=logging_default_handler):
if has_handlers(logger): if logger.hasHandlers():
logger.removeHandler(handler) logger.removeHandler(handler)
# Version information. # Version information.
from theano.version import version as __version__ from theano.version import version as __version__
# Raise a meaning full warning/error if the theano directory is in the # Raise a meaningful warning/error if the theano directory is in the Python
# Python path. # path.
from six import PY3
rpath = os.path.realpath(__path__[0]) rpath = os.path.realpath(__path__[0])
for p in sys.path: for p in sys.path:
if os.path.realpath(p) != rpath: if os.path.realpath(p) != rpath:
continue continue
if PY3: raise RuntimeError("You have the theano directory in your Python path.")
raise RuntimeError(
"You have the theano directory in your Python path."
" This do not work in Python 3."
)
else:
warnings.warn(
"You have the theano directory in your Python path."
" This is will not work in Python 3."
)
break
from theano.configdefaults import config from theano.configdefaults import config
from theano.configparser import change_flags from theano.configparser import change_flags
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论