예제 #1
0
    def release(self):
        if self.owner != currentThread():
            if self.owner is None:
                # Release *should* raise an exception...
                self.real_lock.release()
                # ...but it didn't.
                raise _InternalAssertion(
                    "Debug logic failed to track the lock's state",
                    # logtype=msglog.types.DB)
                )
            else:
                raise _WrongThreadAssertion(
                    "Attempt to release another thread's lock",
                    # logtype=msglog.types.DB)
                )

        # Now remove this lock to the list of currently acquired locks.
        self.list_lock.acquire()
        if self in self.locked_list:
            self.locked_list.remove(self)
        else:
            self.list_lock.release()
            self.real_lock.release()
            raise _InternalAssertion(
                "Debug logic failed to properly track the lock's state",
                # logtype=msglog.types.DB)
            )
        self.list_lock.release()
        self.owner = None
        self.real_lock.release()
        return
예제 #2
0
 def release(self):
     if self.owner != currentThread():
         if self.owner is None:
             # Release *should* raise an exception...
             self.real_lock.release()
             # ...but it didn't.
             raise _InternalAssertion(
                 "Debug logic failed to track the lock's state",
                 # logtype=msglog.types.DB)
                 )
         else:
             raise _WrongThreadAssertion(
                 "Attempt to release another thread's lock",
                 # logtype=msglog.types.DB)
                 )
     
     # Now remove this lock to the list of currently acquired locks.
     self.list_lock.acquire()
     if self in self.locked_list:
         self.locked_list.remove(self)
     else:
         self.list_lock.release()
         self.real_lock.release()
         raise _InternalAssertion(
             "Debug logic failed to properly track the lock's state",
             # logtype=msglog.types.DB)
             )
     self.list_lock.release()
     self.owner = None
     self.real_lock.release()
     return
예제 #3
0
 def acquire(self, waitflag=None):
     owner = currentThread()
     if self.owner == owner and waitflag is not 0:
         raise _ReentrantAcquireAssertion('Reentrant lock attempt',
                                          # logtype=msglog.types.DB)
                                          )
     if waitflag is None:
         result = self.real_lock.acquire()
     else:
         result = self.real_lock.acquire(waitflag)
         if not waitflag and not result:
             # We did not acquire the lock and we are in non-blocking
             # mode.
             return result
     self.owner = owner
     # Now add this lock to the list of currently acquired locks.
     self.list_lock.acquire()
     self.locked_list.append(self)
     self.list_lock.release()
     return result
예제 #4
0
 def acquire(self,waitflag=None):
     owner = currentThread()
     if self.owner == owner and waitflag is not 0:
         raise _ReentrantAcquireAssertion('Reentrant lock attempt',
                                          # logtype=msglog.types.DB)
                                          )
     if waitflag is None:
         result = self.real_lock.acquire()
     else:
         result = self.real_lock.acquire(waitflag)
         if not waitflag and not result:
             # We did not acquire the lock and we are in non-blocking
             # mode.
             return result
     self.owner = owner
     # Now add this lock to the list of currently acquired locks.
     self.list_lock.acquire()
     self.locked_list.append(self)
     self.list_lock.release()
     return result
예제 #5
0
 def acquire(self, blocking=1):
     if not blocking:
         return self.real_lock.acquire(blocking)
     # Wait up to timeout seconds to acquire the lock.  If we can't, then
     # raise some hell.
     st_time = uptime.secs()
     while 1:
         result = self.real_lock.acquire(0)
         if result:
             self.locker = currentThread()
             # We got our lock, return
             return result
         cur_time = uptime.secs()
         if cur_time - st_time > self.timeout:
             break
         time.sleep(.1)
     # If we get here, we didn't acquire our lock in time.
     # self._logMsg('Possible deadlock warning!!')
     mstr = ("Could not acquire lock (%s) within %d seconds!  "
             "Locker is %s.") % (str(
                 self.name), self.timeout, str(self.locker))
     raise _LockAssertion(mstr)
예제 #6
0
 def acquire(self, blocking=1):
     if not blocking:
         return self.real_lock.acquire(blocking)
     # Wait up to timeout seconds to acquire the lock.  If we can't, then
     # raise some hell.
     st_time = uptime.secs()
     while 1:
         result = self.real_lock.acquire(0)
         if result:
             self.locker = currentThread()
             # We got our lock, return
             return result
         cur_time = uptime.secs()
         if cur_time - st_time > self.timeout:
             break
         time.sleep(.1)
     # If we get here, we didn't acquire our lock in time.
     # self._logMsg('Possible deadlock warning!!')
     mstr  = ("Could not acquire lock (%s) within %d seconds!  "
              "Locker is %s.") % (
         str(self.name), self.timeout, str(self.locker)
         )
     raise _LockAssertion(mstr)