1
# gozerbot/utils/locking.py
5
""" generic functions """
7
__copyright__ = 'this file is in the public domain'
9
from log import rlog, loglevel
10
from trace import whichmodule
11
from lockmanager import lockmanager, rlockmanager
18
""" locking decorator. """
22
""" locking function for %s """ % str(func)
24
def lockedfunc(*args, **kwargs):
25
""" the locked function. """
28
where = whichmodule(1)
29
rlog(1, 'locking', 'locking on %s (%s)' % (where, str(func)))
31
locks.append(str(func))
35
res = func(*args, **kwargs)
38
locks.remove(str(func))
48
""" locking function for %s """ % str(func)
50
def lockedfunc(*args, **kwargs):
52
""" the locked function. """
55
where = whichmodule(1)
56
rlog(1, 'locking', 'locking on %s' % where)
57
rlockmanager.acquire(func)
58
locks.append(str(func))
62
res = func(*args, **kwargs)
64
rlockmanager.release(func)
65
locks.remove(str(func))
74
""" class used to lock an entire object. """
76
def __getattribute__(self, attr):
78
where = whichmodule(1)
79
rlog(1, 'locking', 'locking on %s' % where)
80
rlockmanager.acquire(object)
84
res = super(Locked, self).__getattribute__(attr)
86
rlockmanager.release(object)