/offlineimap/head: changeset 310

Added some temporary debug code to help weed out a few race conditions
with the curses Blinkenlights interface. Think I've finally got it.
I'm leaving the debugging code in for now, though, to help in case
there are future problems.
This commit is contained in:
jgoerzen 2003-01-06 12:07:16 +01:00
parent 2b9c425091
commit 752b7d84e7
3 changed files with 57 additions and 8 deletions

View File

@ -20,6 +20,8 @@ from threading import *
from offlineimap.ui.UIBase import UIBase
import thread
from debuglock import DebuggingLock
class BlinkenBase:
"""This is a mix-in class that should be mixed in with either UIBase
or another appropriate base class. The Tk interface, for instance,
@ -73,7 +75,7 @@ class BlinkenBase:
def init_banner(s):
s.availablethreadframes = {}
s.threadframes = {}
s.tflock = Lock()
s.tflock = DebuggingLock('tflock')
def threadExited(s, thread):
threadid = thread.threadid
@ -94,6 +96,7 @@ class BlinkenBase:
threadid = thread.get_ident()
accountname = s.getthreadaccount()
if lock:
s.tflock.acquire()
try:
@ -115,6 +118,7 @@ class BlinkenBase:
return tf
finally:
if lock:
s.tflock.release()

View File

@ -22,6 +22,7 @@ from threading import *
from offlineimap import version, threadutil
import curses, curses.panel, curses.textpad, curses.wrapper
from debuglock import DebuggingLock
class CursesUtil:
def __init__(self):
@ -138,6 +139,7 @@ class CursesThreadFrame:
self.iolock.acquire()
try:
self.window.addstr(self.y, self.x, '.', self.color)
self.c.stdscr.move(self.c.height - 1, self.c.width - 1)
self.window.refresh()
finally:
if lock:
@ -163,9 +165,9 @@ class InputHandler:
def __init__(s, util):
s.c = util
s.bgchar = None
s.inputlock = Lock()
s.inputlock = DebuggingLock('inputlock')
s.lockheld = 0
s.statuslock = Lock()
s.statuslock = DebuggingLock('statuslock')
s.startup = Event()
s.startthread()
@ -232,9 +234,9 @@ class InputHandler:
class Blinkenlights(BlinkenBase, UIBase):
def init_banner(s):
s.iolock = Lock()
s.iolock = DebuggingLock('iolock')
s.af = {}
s.aflock = Lock()
s.aflock = DebuggingLock('aflock')
s.c = CursesUtil()
s.text = []
BlinkenBase.init_banner(s)

View File

@ -0,0 +1,43 @@
# Locking debugging code -- temporary
# Copyright (C) 2003 John Goerzen
# <jgoerzen@complete.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from threading import *
import traceback
logfile = open("/tmp/logfile", "wt")
class DebuggingLock:
def __init__(self, name):
self.lock = Lock()
self.name = name
def acquire(self, blocking = 1):
self.print_tb("Acquire lock")
self.lock.acquire(blocking)
logfile.write("===== %s: Thread %s acquired lock\n" % (self.name, currentThread().getName()))
def release(self):
self.print_tb("Release lock")
self.lock.release()
def print_tb(self, msg):
logfile.write("==== %s: Thread %s attempting to %s\n" % \
(self.name, currentThread().getName(), msg))
logfile.write("\n".join(traceback.format_list(traceback.extract_stack())))
logfile.write("\n")
logfile.flush()