python - Snakemake:使用 Python fileConfig() 时缺少 RuntimeError 堆栈跟踪
问题描述
我有一个带有一条规则的蛇文件,它导入本地 Python 脚本,然后引发RuntimeError
. 当我运行蛇文件时,没有显示堆栈跟踪RuntimeError
。代码和snakemake 输出如下所示。
// test.snakefile
rule test_rule:
run:
from test import hello
print(hello)
raise RuntimeError('raising error')
// test.py
import logging
import os
from logging.config import fileConfig
log_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logging_config.ini')
fileConfig(log_file_path)
hello = 'hello'
蛇形输出:
...
[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
但是,如果我注释掉其中的行fileConfig(log_file_path)
并test.py
运行snakemake,则会按预期打印 RuntimeError 堆栈跟踪:
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
有谁知道为什么会这样?
编辑:logging_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
解决方案
这个问题与如何logging
定义模块test.py
以及如何在Snakefile
. 以下设置应该可以工作。请注意代码块内的注释以了解修改的描述。
测试.py
import logging
import os
from logging.config import fileConfig
fileConfig('logging_config.ini')
logger = logging.getLogger(__name__) # assigns to "logger", through which logs are passed.
logger.info('test.py debug msg') # example log message
hello = 'yo yo yo'
蛇文件
rule test_rule:
run:
from test import hello, logger. # imports both hello and logger
print(hello)
print (logger)
logger.exception("Exception occurred") # error log that would capture stack traces, if any. No stack trace in this example.
raise SystemExit(1) # exits with non-zero error
logging_config.ini - 与问题中发布的相同。
在这个设置中,变量hello
和类logger
被导入到 ruletest_rule
中,并且它们的日志输出被写入到 file/tmp/experiments.log
中,如logging_config.ini
.
推荐阅读
- python - Kivy ProgressBar 弹出窗口未正确显示
- c# - 从 ASP.NET Core 中创建的 cookie 获取信息
- llvm - 如何知道是否可以在 LLVM 中间接调用函数?
- pdf - 渲染文档时 Autodesk PDF Forge 查看器错误
- javascript - 为什么删除行方法会删除整个表?
- javascript - ActiveSupport::MessageVerifier::InvalidSignature
- sql - 在选择 sqloracle 中展开 *
- typescript - 如何定义字符串类型的任何属性不包括某些属性
- python-3.x - 熊猫合并意外产生后缀
- javascript - 使用 react.js 从文件数组中删除文件