def wait_on_any(*events, **kwargs):
timeout = kwargs.get("<STR_LIT>")<EOL>composite_event = threading.Event()<EOL>if any([event.is_set() for event in events]):<EOL><INDENT>return<EOL><DEDENT>def on_change():<EOL><INDENT>if any([event.is_set() for event in events]):<EOL><INDENT>composite_event.set()<EOL><DEDENT>else:<EOL><INDENT>composite_event.clear()<EOL><DEDENT><DEDENT>def patch(original):<EOL><INDENT>def patched():<EOL><INDENT>original()<EOL>on_change()<EOL><DEDENT>return patched<EOL><DEDENT>for event in events:<EOL><INDENT>event.set = patch(event.set)<EOL>event.clear = patch(event.clear)<EOL><DEDENT>wait_on_event(composite_event, timeout=timeout)<EOL>
Helper method for waiting for any of the given threading events to be
set.

The standard threading lib doesn't include any mechanism for waiting on
more than one event at a time so we have to monkey patch the events
so that their `set()` and `clear()` methods fire a callback we can use
to determine how a composite event should react.