/usr/share/pyshared/jsb/utils/lockmanager.py is in jsonbot 0.84.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | # jsb/utils/lockmanager.py
#
#
""" manages locks """
## basic imports
import thread
import threading
import logging
## LockManager class
class LockManager(object):
""" place to hold locks """
def __init__(self):
self.locks = {}
try:
import waveapi
self.gae = True
except ImportError: self.gae = False
def allocate(self, name):
""" allocate a new lock """
if self.gae: self.locks[name] = None
else: self.locks[name] = thread.allocate_lock()
logging.debug('lockmanager - allocated %s' % name)
def get(self, name):
""" get lock """
if not self.locks.has_key(name): self.allocate(name)
return self.locks[name]
def delete(self, name):
""" delete lock """
if self.locks.has_key(name): del self.locks[name]
def acquire(self, name):
""" acquire lock """
if self.gae: return
if not self.locks.has_key(name): self.allocate(name)
logging.debug('lockmanager - *acquire* %s' % name)
self.locks[name].acquire()
def release(self, name):
""" release lock """
if self.gae: return
logging.debug('lockmanager - *releasing* %s' % name)
try: self.locks[name].release()
except RuntimeError: pass
## RLockManager class
class RLockManager(LockManager):
def allocate(self, name):
""" allocate a new lock """
self.locks[name] = threading.RLock()
logging.debug('lockmanager - allocated RLock %s' % name)
## global lockmanagers
lockmanager = LockManager()
rlockmanager = RLockManager()
|