From 200019574d66c1a04d25e23eb0a0fcda7c25f445 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Sun, 6 Nov 2011 17:08:40 +0100 Subject: Use threads RLock to avoid crash on simultaneous refresh and resize. fixes #2180 --- src/windows.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/windows.py') diff --git a/src/windows.py b/src/windows.py index 42c9bfa0..790dd858 100644 --- a/src/windows.py +++ b/src/windows.py @@ -24,7 +24,7 @@ import curses import string from config import config -from threading import Lock +from threading import RLock from contact import Contact, Resource from roster import RosterGroup, roster @@ -46,7 +46,7 @@ allowed_color_digits = ('0', '1', '2', '3', '4', '5', '6', '7') # first is a bool telling if this is the first line of the message. Line = collections.namedtuple('Line', 'msg start_pos end_pos') -g_lock = Lock() +g_lock = RLock() LINES_NB_LIMIT = 4096 @@ -79,7 +79,8 @@ class Win(object): """ Override if something has to be done on resize """ - self._resize(height, width, y, x) + with g_lock: + self._resize(height, width, y, x) def _refresh(self): self._win.noutrefresh() @@ -255,10 +256,11 @@ class UserList(Win): self._refresh() def resize(self, height, width, y, x): - self._resize(height, width, y, x) - self._win.attron(to_curses_attr(get_theme().COLOR_VERTICAL_SEPARATOR)) - self._win.vline(0, 0, curses.ACS_VLINE, self.height) - self._win.attroff(to_curses_attr(get_theme().COLOR_VERTICAL_SEPARATOR)) + with g_lock: + self._resize(height, width, y, x) + self._win.attron(to_curses_attr(get_theme().COLOR_VERTICAL_SEPARATOR)) + self._win.vline(0, 0, curses.ACS_VLINE, self.height) + self._win.attroff(to_curses_attr(get_theme().COLOR_VERTICAL_SEPARATOR)) class Topic(Win): def __init__(self): @@ -674,9 +676,10 @@ class TextWin(Win): self.addstr(' ') def resize(self, height, width, y, x, room=None): - self._resize(height, width, y, x) - if room: - self.rebuild_everything(room) + with g_lock: + self._resize(height, width, y, x) + if room: + self.rebuild_everything(room) def rebuild_everything(self, room): self.built_lines = [] -- cgit v1.2.3