Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Snakemake:使用Python fileConfig()时缺少运行时错误堆栈跟踪_Python_Logging_Snakemake - Fatal编程技术网

Snakemake:使用Python fileConfig()时缺少运行时错误堆栈跟踪

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,它导入一个本地Python脚本,然后引发一个
运行时错误
。当我运行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