Python http.server未打印日志

7
我正在使用Git Bash运行一个简单的本地服务器,命令是$ python3 -m http.server 8000。
Git Bash从未打印正在运行的消息,并且没有记录请求。我可以访问http://localhost:8000/,因此该命令有效。如何让Git Bash打印日志?

有其他人遇到了同样的问题:https://stackoverflow.com/questions/35657355/python-logging-to-stdout-in-git-bash - fuglede
2个回答

9

看起来这是在 mingw 下出现的一般性行缓冲问题。您可以通过避免缓冲输出来解决这个问题,对于您的情况来说是可能的,方式如下:

$ python -u -m http.server 8080

这在技术方面是正常的

$ uname -a
MINGW64_NT-6.3 - 2.5.0(0.295/5/3) 2016-03-31 18:47 x86_64 Msys

对我有用,谢谢! - Soheil Hosseini

1

从Git Bash的外观来看,它似乎是Cygwin的简化版本。我刚刚运行了“python3 -m http.server 8000”命令,得到以下日志输出:

$ python3 -m http.server 8000
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
127.0.0.1 - - [04/Jun/2017 20:15:10] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [04/Jun/2017 20:15:10] code 404, message File not found
127.0.0.1 - - [04/Jun/2017 20:15:10] "GET /favicon.ico HTTP/1.1" 404 -
127.0.0.1 - - [04/Jun/2017 20:15:10] code 404, message File not found
127.0.0.1 - - [04/Jun/2017 20:15:10] "GET /favicon.ico HTTP/1.1" 404 -

似乎 git bash 无法正确记录(输出)。
尝试在虚拟机 / vagrant 中的 Ubuntu 或 Centos 上运行“python3 -m http.server 8000”。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接