Python threading.Event-如何设置();_set()在内部工作吗?

Python threading.Event-如何设置();_set()在内部工作吗?,python,multithreading,events,generator,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 = thre

在下面的代码中

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()。是什么让你认为任何队列或事件处理都与此有关?这种奇怪的事件处理可以在线程之间使用。那么,内部使用的共享资源是什么?让一个线程读取其他线程..不管底层操作系统有什么。在posix上,它是带条件的互斥。@freakish OK,这是原子同步(例如:锁)还是条件同步(例如:计数信号量),但不是内部的事件信号量?
set()
获取一个锁,它在使用基于信号量锁的posix构建上调用
sem\u wait
。Windows上的锁定默认使用模拟条件变量,使用临界部分和信号量。