]> code.delx.au - offlineimap/blob - offlineimap/ui/debuglock.py
Update FSF address
[offlineimap] / offlineimap / ui / debuglock.py
1 # Locking debugging code -- temporary
2 # Copyright (C) 2003 John Goerzen
3 # <jgoerzen@complete.org>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 from threading import *
20 import traceback
21 logfile = open("/tmp/logfile", "wt")
22 loglock = Lock()
23
24 class DebuggingLock:
25 def __init__(self, name):
26 self.lock = Lock()
27 self.name = name
28
29 def acquire(self, blocking = 1):
30 self.print_tb("Acquire lock")
31 self.lock.acquire(blocking)
32 self.logmsg("===== %s: Thread %s acquired lock\n" % (self.name, currentThread().getName()))
33
34 def release(self):
35 self.print_tb("Release lock")
36 self.lock.release()
37
38 def logmsg(self, msg):
39 loglock.acquire()
40 logfile.write(msg + "\n")
41 logfile.flush()
42 loglock.release()
43
44 def print_tb(self, msg):
45 self.logmsg(".... %s: Thread %s attempting to %s\n" % \
46 (self.name, currentThread().getName(), msg) + \
47 "\n".join(traceback.format_list(traceback.extract_stack())))
48
49