Snakemake:使用Python fileConfig()时缺少运行时错误堆栈跟踪
我有一个带有一条规则的snakefile,它导入一个本地Python脚本,然后引发一个Snakemake:使用Python fileConfig()时缺少运行时错误堆栈跟踪,python,logging,snakemake,Python,Logging,Snakemake,我有一个带有一条规则的snakefile,它导入一个本地Python脚本,然后引发一个运行时错误。当我运行snakefile时,不会显示RuntimeError的堆栈跟踪。代码和snakemake输出如下所示 // test.snakefile rule test_rule: run: from test import hello print(hello) raise RuntimeError('raising error') 蛇形输出:
运行时错误
。当我运行snakefile时,不会显示RuntimeError
的堆栈跟踪。代码和snakemake输出如下所示
// test.snakefile
rule test_rule:
run:
from test import hello
print(hello)
raise RuntimeError('raising error')
蛇形输出:
...
[Mon Jan 13 14:45:54 2020]
rule test_rule:
jobid: 0
Job counts:
count jobs
1 test_rule
1
hello
Shutting down, this might take some time.
Exiting because a job execution failed. Look above for error message
但是,如果我注释掉test.py
中的fileConfig(log\u file\u path)
行并运行snakemake,运行时错误堆栈跟踪将按预期打印:
Error in rule test_rule:
jobid: 0
RuleException:
RuntimeError in line 5 of /my-dir/test.snakefile:
raising error
File "/my-dir/test.snakefile", line 5, in __rule_test_rule
File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
Exiting because a job execution failed. Look above for error message
有人知道为什么会这样吗
编辑:
日志记录\u config.ini
[loggers]
keys=root
[handlers]
keys=stream_handler
[formatters]
keys=formatter
[logger_root]
level=INFO
handlers=stream_handler
[handler_stream_handler]
class=handlers.TimedRotatingFileHandler
level=DEBUG
formatter=formatter
args=('/tmp/experiments.log', 'midnight')
[formatter_formatter]
format=%(asctime)s %(name)-12s %(levelname)-8s %(message)s
这个问题与
test.py
中如何定义logging
模块以及如何在Snakefile
中导入模块有关。下面的设置应该可以工作。请注意代码块内的注释,以了解修改说明
test.py
导入日志
导入操作系统
从logging.config导入fileConfig
fileConfig('logging_config.ini')
logger=logging.getLogger(_名称__)#分配给“logger”,日志通过它传递。
logger.info('test.py debug msg')#示例日志消息
你好=‘溜溜球’
蛇锉
规则测试\u规则:
运行:
来自测试导入你好,logger.#导入hello和logger
打印(您好)
打印(记录器)
logger.exception(“异常发生”)#将捕获堆栈跟踪(如果有)的错误日志。本例中没有堆栈跟踪。
raise SystemExit(1)#退出时出现非零错误
logging_config.ini-与问题中发布的相同
在此设置中,变量
hello
和类logger
被导入规则test\u rule
,它们的日志输出被写入文件/tmp/experiments.log
,如logging\u config.ini
中配置的,您能显示logging\u config.ini
的内容吗?想知道stderr
是否被重定向到配置中指定的某个文件。是否也应该打印hello?@Maarten vd Sande是的,hello打印在堆栈跟踪上方,我只是没有在帖子中复制它。@ManavalanGajapathy编辑了帖子,将日志记录\u config.ini
!看起来此错误是由于日志设置而不是snakemake的。我认为,如果您将run
部分中的代码作为单独的python脚本执行,您也会遇到同样的问题。您是否检查了/tmp/experiments.log
以查看错误消息是否重定向到那里?此外,您可能需要添加。
[loggers]
keys=root
[handlers]
keys=stream_handler
[formatters]
keys=formatter
[logger_root]
level=INFO
handlers=stream_handler
[handler_stream_handler]
class=handlers.TimedRotatingFileHandler
level=DEBUG
formatter=formatter
args=('/tmp/experiments.log', 'midnight')
[formatter_formatter]
format=%(asctime)s %(name)-12s %(levelname)-8s %(message)s