python - sys.stdin 如何在 Python 中缓冲?
问题描述
我正在开发一个接受来自 Apache 的日志输出的脚本。我的解决方案如下:
while True:
log_line = sys.stdin.readline()
while(log_line == ""): # wait for new line
time.sleep(2)
log_line = sys.stdin.readline() # buffer issue?
# process the line here
问题是,在观察 apache 日志和我的脚本处理的行日志之间的差异时,我注意到我的程序缺少一些行。我希望这一定与在时间延迟期间被丢弃/覆盖的行有关,但我无法找到有关 Python 的 std.in 如何缓冲的深入信息。
我的假设是,如果在 time.sleep(2) 期间将多行发送到 std.in,它们将被缓冲并最终通过后续的 sys.stdin.readline() 调用访问。这不正确吗?
解决方案
推荐阅读
- java - Java .bin 文件被编写为标准 .txt 文件
- r - GGAnimate 包没有加载 gif
- python - 无法生成csv文件或考勤系统
- docker - 用于备份和恢复 Kubernetes 集群 Heptio Ark 的基于角色的访问控制身份验证
- mysql - MySQL游标和while循环有什么区别
- regex - 用于匹配除多位数字之外的所有内容的正则表达式
- javascript - 无法为 React 日历设置类名
- asp.net - 如何在 IIS 10 服务器场上跟踪失败的请求
- apache - 静态文件的 Apache 代理通行证
- python - 如何将 i18n 扩展添加到 jinja?