]>
code.delx.au - offlineimap/blob - offlineimap/ui/debuglock.py
1 # Locking debugging code -- temporary
2 # Copyright (C) 2003 John Goerzen
3 # <jgoerzen@complete.org>
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.
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.
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
19 from threading
import *
21 logfile
= open("/tmp/logfile", "wt")
25 def __init__(self
, name
):
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()))
35 self
.print_tb("Release lock")
38 def logmsg(self
, msg
):
40 logfile
.write(msg
+ "\n")
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())))