License | |
Info | |
Tests |
multievent
provides a easy API to wait on multiple events.
python -m pip install git+https://github.com/karthiknadig/multievent
events = [threading.Event() for _ in range(0, 5)]
# Default is ANY
wait = wait_for_multiple_events(events)
# wait blocks until one of the events is set.
wait()
events = [threading.Event() for _ in range(0, 5)]
# Default is ANY
wait = wait_for_multiple_events(events, mode=MODE_ALL)
# wait blocks until all of the events are set.
wait()
events = [threading.Event() for _ in range(0, 5)]
cancel = CancelWait()
# Default is ANY
wait = wait_for_multiple_events(events, cancel=cancel)
def _run_this():
time.sleep(5)
cancel() # see NOTE below.
t = threading.Thread(target=_run_this)
t.start()
# wait is blocked until either one of the events is set or
# cancel is called
wait()
# NOTE: Cancellation ends all monitoring. You have to call
# wait_for_multiple_events, and get a new wait function.
events = [threading.Event() for _ in range(0, 5)]
# Default is ANY
wait = wait_for_multiple_events(events, mode=MODE_COUNT, count=3)
# wait blocks until three events are set.
wait()