Acquire a lock, blocking or non-blocking. When invoked without arguments: if this thread already owns the lock, increment the recursion level by one, and return immediately. Otherwise, if another thread owns the lock, block until the lock is unlocked. Once the l
(self, blocking=True, timeout=-1)
| 136 | self._count = 0 |
| 137 | |
| 138 | def acquire(self, blocking=True, timeout=-1): |
| 139 | """Acquire a lock, blocking or non-blocking. |
| 140 | |
| 141 | When invoked without arguments: if this thread already owns the lock, |
| 142 | increment the recursion level by one, and return immediately. Otherwise, |
| 143 | if another thread owns the lock, block until the lock is unlocked. Once |
| 144 | the lock is unlocked (not owned by any thread), then grab ownership, set |
| 145 | the recursion level to one, and return. If more than one thread is |
| 146 | blocked waiting until the lock is unlocked, only one at a time will be |
| 147 | able to grab ownership of the lock. There is no return value in this |
| 148 | case. |
| 149 | |
| 150 | When invoked with the blocking argument set to true, do the same thing |
| 151 | as when called without arguments, and return true. |
| 152 | |
| 153 | When invoked with the blocking argument set to false, do not block. If a |
| 154 | call without an argument would block, return false immediately; |
| 155 | otherwise, do the same thing as when called without arguments, and |
| 156 | return true. |
| 157 | |
| 158 | When invoked with the floating-point timeout argument set to a positive |
| 159 | value, block for at most the number of seconds specified by timeout |
| 160 | and as long as the lock cannot be acquired. Return true if the lock has |
| 161 | been acquired, false if the timeout has elapsed. |
| 162 | |
| 163 | """ |
| 164 | me = get_ident() |
| 165 | if self._owner == me: |
| 166 | self._count += 1 |
| 167 | return 1 |
| 168 | rc = self._block.acquire(blocking, timeout) |
| 169 | if rc: |
| 170 | self._owner = me |
| 171 | self._count = 1 |
| 172 | return rc |
| 173 | |
| 174 | __enter__ = acquire |
| 175 |
no outgoing calls
no test coverage detected