Jupyter Notebook日志记录ValueError:对已关闭文件的I / O操作

时间:2019-05-07 16:53:03

标签: python logging pyspark jupyter-notebook

我正在尝试将日志记录添加到一些Jupyter Notebook代码(运行Pyspark3)。

在SO中进行挖掘,我发现了一些答案,这些回答说使用basicConfig()不起作用,因为笔记本启动了自己的日志记录会话。一些解决方法的答案指向运行reload(logging)以解决此问题。考虑到这一点,我正在这样设置日志记录:

from importlib import reload  # Not needed in Python 2
import logging
reload(logging)
logging.basicConfig(
    format="%(asctime)s - %(levelname)s - %(name)s - %(message)s",
    level=logging.INFO,
    datefmt="%y/%m/%d %H:%M:%S",
)
logger = logging.getLogger(__name__)

然后我运行一条信息语句:logger.info("this is a test"),并收到I / O值错误?我不确定这意味着什么。

--- Logging error ---
Traceback (most recent call last):
  File "/usr/lib64/python3.6/logging/__init__.py", line 994, in emit
    stream.write(msg)
  File "/tmp/2950371398694308674", line 534, in write
    super(UnicodeDecodingStringIO, self).write(s)
ValueError: I/O operation on closed file
Call stack:
  File "/tmp/2950371398694308674", line 700, in <module>
    sys.exit(main())
  File "/tmp/2950371398694308674", line 672, in main
    response = handler(content)
  File "/tmp/2950371398694308674", line 318, in execute_request
    result = node.execute()
  File "/tmp/2950371398694308674", line 229, in execute
    exec(code, global_dict)
  File "<stdin>", line 1, in <module>
Message: 'this is a test'
Arguments: ()

这与与stdout / stderr交互的日志记录有关,但是我不确定如何解决它。

0 个答案:

没有答案