Back to index
|struct _typeobject *||ob_type|
|__enter__ = acquire|
Class implementing dummy implementation of _thread.LockType. Compatibility is maintained by maintaining self.locked_status which is a boolean that stores the state of the lock. Pickling of the lock, though, should not be done since if the _thread module is then used with an unpickled ``lock()`` from here problems could occur from this class not having atomic methods.
Dummy implementation of acquire(). For blocking calls, self.locked_status is automatically set to True and returned appropriately based on value of ``waitflag``. If it is non-blocking, then the value is actually checked and not set if it is already acquired. This is all done so that threading.Condition's assert statements aren't triggered and throw a little fit.
00102 00103 def acquire(self, waitflag=None, timeout=-1): 00104 """Dummy implementation of acquire(). 00105 00106 For blocking calls, self.locked_status is automatically set to 00107 True and returned appropriately based on value of 00108 ``waitflag``. If it is non-blocking, then the value is 00109 actually checked and not set if it is already acquired. This 00110 is all done so that threading.Condition's assert statements 00111 aren't triggered and throw a little fit. 00112 00113 """ 00114 if waitflag is None or waitflag: 00115 self.locked_status = True 00116 return True 00117 else: 00118 if not self.locked_status: 00119 self.locked_status = True 00120 return True 00121 else: 00122 if timeout > 0: 00123 import time 00124 time.sleep(timeout) 00125 return False
Release the dummy lock.
00131 00132 def release(self): 00133 """Release the dummy lock.""" 00134 # XXX Perhaps shouldn't actually bother to test? Could lead 00135 # to problems for complex, threaded code. 00136 if not self.locked_status: 00137 raise error 00138 self.locked_status = False 00139 return True