# kern/utils/lock.py
#
#
""" utils package. """
__copyright__ = "Copyright 2015, B.H.J Thate"
## IMPORT
import _thread
## LOCK
[docs]def locked(func, *args, **kwargs):
""" locking function for %s """ % str(func)
lock = _thread.allocate_lock()
def lockedfunc(*args, **kwargs):
""" the locked function. """
lock.acquire()
res = None
try: res = func(*args, **kwargs)
finally:
try: lock.release()
except: pass
return res
return lockedfunc