参考:https://www.cnblogs.com/lixiaoliuer/p/6728789.html    事件驱动和I/O操作

from
multiprocessing import Event e = Event() print(e) # <multiprocessing.synchronize.Event object at 0x0000020167475E10> print(dir(e)) # 查看一个对象的所有属性列表 print(help(e)) # 获取对象的帮助信息 # <multiprocessing.synchronize.Event object at 0x00000258F5605E10> # ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_cond', '_flag', 'clear', 'is_set', 'set', 'wait'] # Help on Event in module multiprocessing.synchronize object: # # class Event(builtins.object) # | Methods defined here: # | # | __init__(self, *, ctx) # | Initialize self. See help(type(self)) for accurate signature. # | # | clear(self) # | # | is_set(self) # | # | set(self) # | # | wait(self, timeout=None) # | # | ---------------------------------------------------------------------- # | Data descriptors defined here: # | # | __dict__ # | dictionary for instance variables (if defined) # | # | __weakref__ # | list of weak references to the object (if defined) # # None


print(e.is_set())  # False # 当实例化一个Event对象时,该对象内部的一个标志位 属性 为 False

print(e.set()) # None 调用此方法,用于设置Event对象内部的标志位为True,该方法没有返回值
print(e.is_set()) # True
print(e.clear()) # None 调用此方法,用于设置Event对象的内部标志为False,相当于清除
print(e.is_set()) # False
print("进程阻塞之前")
e.set()
print(e.wait()) # 当 e.is_set()方法,返回False,则进程运行到e.wait()时,进入阻塞状态,直到e.is_set()返回True
print("进程解除阻塞之后")

# 总结:e.wait()方法,它是判断Event对象e 此时的内部某个属性(想象为flag)是否为True,程序继续向下执行,若为False,进程阻塞,
# 此时进程进入阻塞队列,只有当Event对象e,通过 e.set()方法,设置为True时,进程进入就绪队列,然后os调试执行
 

 

posted on 2018-09-19 14:51  yellwonfin  阅读(202)  评论(0)    收藏  举报