threading.Event - 如何set()& is_set()在内部工作?

时间:2017-07-04 20:34:11

标签: python multithreading events generator

在下面的代码中,

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()内部使用优先级队列进行事件处理?

0 个答案:

没有答案