我正在从stdin中读取,并处理每一行。简化的代码段:
#!/usr/bin/python3
import os, sys, stat
logfile = '/var/log/mylog'
while True:
with open(logfile, 'a', buffering=1) as f:
f_ino = os.stat(logfile)[stat.ST_INO]
for line in sys.stdin:
try:
if os.stat(logfile)[stat.ST_INO] != f_ino:
break
except IOError:
pass
f.write(line)
收到EOF后如何退出脚本?
从字面上什么都不做,您的脚本已经在EOF上退出。