Python threading.Event() - Ensuring all waiting threads wake up on event.set()

后端 未结 4 858
有刺的猬
有刺的猬 2021-02-05 19:20

I have a number of threads which wait on an event, perform some action, then wait on the event again. Another thread will trigger the event when it\'s appropriate.

I can

4条回答
  •  無奈伤痛
    2021-02-05 20:02

    One solution I've used in the past is the Queue class for interthread communication. It is threadsafe and can be used to easy communication between threads when using both the multiprocessing and threading libraries. You could have the child threads waiting for something to enter the queue and then process the new entry. The Queue class also has a get() method which takes a handy blocking argument.

提交回复
热议问题