diff --git a/nomadnet/RRC.py b/nomadnet/RRC.py index c9c26a3..04e212e 100644 --- a/nomadnet/RRC.py +++ b/nomadnet/RRC.py @@ -815,9 +815,11 @@ class RRCHub: self._append_history(target_room, msg) self._clean_history() - def get_messages(self, room): - with self._lock: - buf = list(self.messages.get(room, [])) + def get_messages(self, room, take_lock=True): + if take_lock: + with self._lock: buf = list(self.messages.get(room, [])) + else: buf = list(self.messages.get(room, [])) + return buf def _on_packet(self, data): diff --git a/nomadnet/ui/textui/Channels.py b/nomadnet/ui/textui/Channels.py index 9ea54b0..2bdb882 100644 --- a/nomadnet/ui/textui/Channels.py +++ b/nomadnet/ui/textui/Channels.py @@ -773,20 +773,21 @@ class RoomWidget(urwid.WidgetWrap): if self.hub.clean_last_removed > self.last_history_clean: try: - hub_msgs = self.hub.get_messages(self.room) if (self.hub is not None and self.room is not None) else [] - self.last_history_clean = time.time() - c = self.messagelist.body_len() - old = set() - for i in range(0, c): - msg = None - w = self.messagelist.get_item(i) - if hasattr(w, "_original_widget"): o = w._original_widget - else: o = None - if hasattr(o, "msg"): msg = o.msg - elif hasattr(w, "msg"): msg = w.msg - if msg and not msg in hub_msgs: old.add(i) + with self.hub._lock: + hub_msgs = self.hub.get_messages(self.room, take_lock=False) if (self.hub is not None and self.room is not None) else [] + self.last_history_clean = time.time() + c = self.messagelist.body_len() + old = set() + for i in range(0, c): + msg = None + w = self.messagelist.get_item(i) + if hasattr(w, "_original_widget"): o = w._original_widget + else: o = None + if hasattr(o, "msg"): msg = o.msg + elif hasattr(w, "msg"): msg = w.msg + if msg and not msg in hub_msgs: old.add(i) - for i in reversed(list(old)): self.messagelist.delete_position(i) + for i in reversed(list(old)): self.messagelist.delete_position(i) except Exception as e: RNS.log("Error while cleaning room history", RNS.LOG_ERROR)