为什么 time.sleep() 会破坏 Python 中的 syslog-ng
我一直在尝试使用 syslog-ng 记录脚本输出,但是,如果我使用我的代码中的任何 time.sleep() 函数都会破坏 syslog-ng 并停止记录脚本的输出。
以下是详细信息。
// samplescript.py
import time
while True:
print "hello world"
time.sleep(5)
我使用管道将其输出发送到 syslog-ng,并使用 unix logger 工具,所以我这样称呼脚本;
$ python sampleoutput.py | logger
这不会向我的日志文件生成任何输出。代码很简单,而且可以工作。
顺便一提, 我对 syslog-ng conf 文件没有任何问题,因为如果我使用下面的代码,它会按预期工作。
// samplescript.py
while True:
print "hello world"
问:为什么 time.sleep() 会破坏 syslog-ng?我可以在代码中使用 sleep() 函数吗?
提前致谢。
I have been trying to log a script output with syslog-ng, however, if I use any time.sleep() function in my code, it breaks syslog-ng and stops logging the output of the script.
Here are the details.
// samplescript.py
import time
while True:
print "hello world"
time.sleep(5)
I use pipe to get it's output to syslog-ng, and I use unix logger tool, so I'm calling the script like this;
$ python sampleoutput.py | logger
This is not generating any output to my log file. The code is simple, and working.
By the way,
I don't thing anything wrong with syslog-ng conf file, since if i use the code below, it works as expected.
// samplescript.py
while True:
print "hello world"
Q: why time.sleep() is breaking syslog-ng? Is there any equivalence for sleep() function that I might use on my code?
thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要刷新缓冲的标准输出流:
如何刷新 Python 打印的输出?
You need to flush the buffered stdout-stream:
How to flush output of Python print?