Package XPyLIB :: Module lock
[hide private]
[frames] | no frames]

Source Code for Module XPyLIB.lock

  1  #!/usr/bin/env python 
  2  # -*- coding: utf-8 -*- 
  3  #-------------------------------------------------------------------- 
  4  # Filname: lock.py 
  5  # Author: Mazhugin Aleksey 
  6  # Created: 2008/03/02 
  7  # ID: $Id: $ 
  8  # URL: $URL: $ 
  9  # Copyright: Copyright (c) 2008, Mazhugin Aleksey. 
 10  # License: BSD 
 11  #-------------------------------------------------------------------- 
 12   
 13  """ 
 14  Summary 
 15   
 16  Details... 
 17  """ 
 18   
 19  # Importing 
 20  #import XPyLIB.dbg as dbg ##@ 
 21  import XPyLIB 
 22   
 23  ##:LOGGING:start 
 24  import XPyLIB.xlogging as _xlog 
 25  from functools import wraps 
 26  _log=_xlog.getLogger(__name__) 
 27  _log.disabled=0 
 28  _log_u=_xlog.IndentFormatter.lvlup 
 29  _log_d=_xlog.IndentFormatter.lvldown 
 30  _log_r=_xlog.IndentFormatter.lvlreset 
 31  _log_w=_xlog.IndentFormatter.lvlwrap 
32 -def _log_wl(fun):
33 @wraps(fun) 34 def wrapper(*args, **kwds): 35 return _xlog.IndentFormatter.lvlwraplog(fun,_log)(*args, **kwds)
36 return wrapper 37 ##:LOGGING:end 38 39 try: 40 import thread 41 import threading 42 except: 43 thread=None 44 45 # Start Implementation 46 47 #_lock is used to serialize access to shared data structures in this module. 48 #This needs to be an RLock because fileConfig() creates Handlers and so 49 50 _lock = None 51
52 -def _acquireLock():
53 """ 54 Acquire the module-level lock for serializing access to shared data. 55 56 This should be released with _releaseLock(). 57 """ 58 global _lock 59 if (not _lock) and thread: 60 _lock = threading.RLock() 61 if _lock: 62 _lock.acquire()
63
64 -def _releaseLock():
65 """ 66 Release the module-level lock acquired by calling _acquireLock(). 67 """ 68 if _lock: 69 _lock.release()
70
71 -class srlock(object):
72 """ 73 Static rlock class. 74 """ 75
76 - def __init__(self):
77 """ 78 """ 79 pass
80 81 @staticmethod
82 - def __createLock():
83 """ 84 Acquire a thread lock for serializing access to the level counter. 85 """ 86 ##dbg.fwriteln('IndentFormatter.createLock') ##@ 87 if thread: 88 srlock.__lock = threading.RLock() 89 else: 90 srlock.__lock = None
91 92 @staticmethod
93 - def acquire():
94 """ 95 Acquire thread lock. 96 """ 97 ##dbg.fwriteln('IndentFormatter.acquire') ##@ 98 if srlock.__lock: 99 srlock.__lock.acquire()
100 101 @staticmethod
102 - def release():
103 """ 104 Release thread lock. 105 """ 106 ##dbg.fwriteln('IndentFormatter.release') ##@ 107 if srlock.__lock: 108 srlock.__lock.release()
109
110 -class rlock(object):
111 """ 112 Instance rlock class. 113 """ 114
115 - def __init__(self):
116 """ 117 """ 118 pass
119 120 @staticmethod
121 - def __createLock():
122 """ 123 Acquire a thread lock for serializing access to the level counter. 124 """ 125 ##dbg.fwriteln('IndentFormatter.createLock') ##@ 126 if thread: 127 self.__lock = threading.RLock() 128 else: 129 self.__lock = None
130 131 @staticmethod
132 - def acquire():
133 """ 134 Acquire thread lock. 135 """ 136 ##dbg.fwriteln('IndentFormatter.acquire') ##@ 137 if IndentFormatter.__lock: 138 IndentFormatter.__lock.acquire()
139 140 @staticmethod
141 - def release():
142 """ 143 Release thread lock. 144 """ 145 ##dbg.fwriteln('IndentFormatter.release') ##@ 146 if IndentFormatter.__lock: 147 IndentFormatter.__lock.release()
148 149 # End Implemetation 150 151 #-DEBUG-START------------------------------------------------------------------- 152
153 -def _debug():
154 """ 155 """ 156 ## _log.debug('Debug message') 157 pass
158 159 #-DEBUG-END--------------------------------------------------------------------- 160 161 if __name__=='__main__': 162 _debug() 163