forked from platypush/platypush
Prevent a potential recursion error in wait_for_either
.
We shouldn't overwrite `event._set` and `event._clear` if those values have already been set. Those attributes hold the original references to `Event.set` and `Event.clear` respectively, and the `OrEvent` logic overwrites them with a callback-based logic. This shouldn't happen if those attributes are already present.
This commit is contained in:
parent
af1392b5b9
commit
6f8816d23d
1 changed files with 5 additions and 2 deletions
|
@ -24,8 +24,11 @@ def OrEvent(*events, cls: Type = threading.Event):
|
||||||
or_event.clear()
|
or_event.clear()
|
||||||
|
|
||||||
def _to_or(e, changed_callback: Callable[[], None]):
|
def _to_or(e, changed_callback: Callable[[], None]):
|
||||||
|
if not hasattr(e, "_set"):
|
||||||
e._set = e.set
|
e._set = e.set
|
||||||
|
if not hasattr(e, "_clear"):
|
||||||
e._clear = e.clear
|
e._clear = e.clear
|
||||||
|
|
||||||
e.changed = changed_callback
|
e.changed = changed_callback
|
||||||
e.set = lambda: _or_set(e)
|
e.set = lambda: _or_set(e)
|
||||||
e.clear = lambda: _clear_or(e)
|
e.clear = lambda: _clear_or(e)
|
||||||
|
|
Loading…
Reference in a new issue