Skip to content

Provides a way to wait on multiple events in python.

License

Notifications You must be signed in to change notification settings

karthiknadig/multievent

Repository files navigation

multievent

License GitHub
Info PyPI PyPI
Tests Build Status PyPI

multievent provides a easy API to wait on multiple events.

Installtion

python -m pip install git+https://github.com/karthiknadig/multievent

Usage

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()

Wait for all events

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()

Cancel 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.

Wait for specified count of events

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()

About

Provides a way to wait on multiple events in python.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages