python 在 git bash 中记录到 stdout

标签 python git-bash

我有一个带有日志记录的 python 脚本,该脚本输出到 stdout

logger = logging.getLogger()
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(v_level)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)

当我在 Linux 机器上运行脚本时,它工作得很好,但是当我在 Windows 上的 git-bash 中运行脚本时,控制台没有输出。

有什么想法吗?

最佳答案

查看 this question 中的信息,看起来这很可能是输出缓冲的问题。您可以通过使用 python -u 运行脚本来跳过缓冲。

关于python 在 git bash 中记录到 stdout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35657355/

相关文章:

python - 如果在 Ruby 和 Python 中都允许猴子修补,为什么在 Ruby 中争议更大?

python - 打印包含字符串和 2 个其他变量的变量

python - Winpty 和 Git Bash

git - 如何查看尚未推送的提交列表?

Python subprocess.call 不等待进程完成 blender

python - 从 C# 执行 python 文件时没有输出

python - 控制台通过 PyCharm 中的先前命令进行 Tab 键切换

python - Django/Python 单元测试 : How to Force Exception of Try/Except Block

regex - 当第二个模式不匹配时,以逗号分隔的模式地址执行 sed 命令

git - 在 Git 中更改用于推送的凭据