From 6f8816d23dff18e685142a1189930d67ad0cdf92 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 14 Apr 2024 23:27:13 +0200 Subject: [PATCH] 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. --- platypush/utils/threads.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/platypush/utils/threads.py b/platypush/utils/threads.py index b48b32b487..228a3c77f5 100644 --- a/platypush/utils/threads.py +++ b/platypush/utils/threads.py @@ -24,8 +24,11 @@ def OrEvent(*events, cls: Type = threading.Event): or_event.clear() def _to_or(e, changed_callback: Callable[[], None]): - e._set = e.set - e._clear = e.clear + if not hasattr(e, "_set"): + e._set = e.set + if not hasattr(e, "_clear"): + e._clear = e.clear + e.changed = changed_callback e.set = lambda: _or_set(e) e.clear = lambda: _clear_or(e)