每50-100次调用记录器一次,程序就会崩溃并显示以下跟踪消息:
Mar 20 07:10:14 service.bash[7693]: Fatal Python error: Cannot recover from stack overflow.
Mar 20 07:10:14 service.bash[7693]: Current thread 0x76fa3010 (most recent call first):
Mar 20 07:10:14 service.bash[7693]: File "/usr/lib/python3.5/logging/__init__.py", line 381 in usesTime
Mar 20 07:10:14 service.bash[7693]: File "/usr/lib/python3.5/logging/__init__.py", line 537 in usesTime
Mar 20 07:10:14 service.bash[7693]: File "/usr/lib/python3.5/logging/__init__.py", line 569 in format
Mar 20 07:10:14 service.bash[7693]: File "/usr/lib/python3.5/logging/__init__.py", line 831 in format
Mar 20 07:10:14 service.bash[7693]: File "/usr/lib/python3.5/logging/__init__.py", line 981 in emit
Mar 20 07:10:14 service.bash[7693]: File "/usr/lib/python3.5/logging/__init__.py", line 856 in handle
Mar 20 07:10:14 service.bash[7693]: File "/usr/lib/python3.5/logging/__init__.py", line 1488 in callHandlers
Mar 20 07:10:14 service.bash[7693]: File "/usr/lib/python3.5/logging/__init__.py", line 1426 in handle
Mar 20 07:10:14 service.bash[7693]: File "/usr/lib/python3.5/logging/__init__.py", line 1416 in _log
Mar 20 07:10:14 service.bash[7693]: File "/usr/lib/python3.5/logging/__init__.py", line 1280 in info
Mar 20 07:10:14 service.bash[7693]: File "*****************_app/base.py", line 63 in log_this
您知道是什么原因导致此崩溃吗?
在程序崩溃的其他地方看不到类似或其他日志记录调用。
以下是对记录器的调用堆栈:
self.info("cs={} miso={} mosi{} clk{}".format( self.csPin, self.misoPin, self.mosiPin, self.clkPin))
|
self.log_this("info", msg)
|
self.log.info(msg)
通过以下方式在基类初始化例程中设置记录器:
# Global logger is declared as a class attribute
cls.log = logging.getLogger(cls.args["app"])
c_handler = logging.StreamHandler()
f_handler = logging.handlers.RotatingFileHandler(
cls.args["--log"],
maxBytes=(10**6)*int(cls.args["--logsize"]), # CLI is in MB
backupCount=1)
# Create handlers
if cls.args["--debug"]:
cls.log.setLevel(logging.DEBUG)
c_handler.setLevel(logging.DEBUG)
f_handler.setLevel(logging.DEBUG)
else:
cls.log.setLevel(logging.INFO)
c_handler.setLevel(logging.INFO)
f_handler.setLevel(logging.INFO)
# Create formatters and add it to handlers
c_format = logging.Formatter('%(name)s: %(levelname)s: %(message)s')
f_format = logging.Formatter('%(asctime)s: %(name)s: %(levelname)s: %(message)s')
c_handler.setFormatter(c_format)
f_handler.setFormatter(f_format)
# Add handlers to the logger
cls.log.addHandler(c_handler)
cls.log.addHandler(f_handler)
cls.log.info("Logger initialized")
谢谢。
答案 0 :(得分:0)
您能提供更多背景信息吗?
查看导致错误的代码段将非常有帮助
答案 1 :(得分:0)
您是否正在使用Windows并在Python中切换到UTF8语言环境?在这种特定情况下存在一个Python错误(类似问题:https://bugs.python.org/issue36792)。这是一个最小的代码示例,可重现我机器上的错误:
import locale
import logging
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter('%(asctime)s'))
logging.getLogger().setLevel(logging.DEBUG)
logging.getLogger().addHandler(handler)
logging.info(1)
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
logging.info(2)
输出:
2019-10-25 21:20:15,657
Process finished with exit code -1073740940 (0xC0000374)
如果不确定这是否与您的问题有关,请尝试在调用日志记录模块的前面添加以下行,看看它是否可以解决问题:
locale.setlocale(locale.LC_ALL, 'en_US')