]>
code.delx.au - offlineimap/blob - offlineimap/head/offlineimap/ui/debuglock.py
e8c817031aab94de6ab23d935fe322e97176e4e9
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; version 2 of the License.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 from threading
import *
20 logfile
= open("/tmp/logfile", "wt")
24 def __init__(self
, name
):
28 def acquire(self
, blocking
= 1):
29 self
.print_tb("Acquire lock")
30 self
.lock
.acquire(blocking
)
31 self
.logmsg("===== %s: Thread %s acquired lock\n" % (self
.name
, currentThread().getName()))
34 self
.print_tb("Release lock")
37 def logmsg(self
, msg
):
39 logfile
.write(msg
+ "\n")
43 def print_tb(self
, msg
):
44 self
.logmsg(".... %s: Thread %s attempting to %s\n" % \
45 (self
.name
, currentThread().getName(), msg
) + \
46 "\n".join(traceback
.format_list(traceback
.extract_stack())))