在下面的代码中,
import time
import threading, signal
def follow(theFile, shutDown=None):
theFile.seek(0, 2)
while True:
if shutDown and shutDown.is_set(): break
line = theFile.readline()
if line:
yield line
shutDown = threading.Event()
def sigusr1(signo,frame):
print("Closing it down")
shutDown.set()
if __name__ == '__main__':
signal.signal(signal.SIGUSR1,sigusr1)
lines = follow(open("access-log"), shutDown)
for line in lines:
print(line)
set()
& is_set()
内部使用优先级队列进行事件处理?