MCPcopy Index your code
hub / github.com/python/cpython / acquire

Method acquire

Lib/threading.py:174–208  ·  view source on GitHub ↗

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 lock i

(self, blocking=True, timeout=-1)

Source from the content-addressed store, hash-verified

172 self._count = 0
173
174 def acquire(self, blocking=True, timeout=-1):
175 """Acquire a lock, blocking or non-blocking.
176
177 When invoked without arguments: if this thread already owns the lock,
178 increment the recursion level by one, and return immediately. Otherwise,
179 if another thread owns the lock, block until the lock is unlocked. Once
180 the lock is unlocked (not owned by any thread), then grab ownership, set
181 the recursion level to one, and return. If more than one thread is
182 blocked waiting until the lock is unlocked, only one at a time will be
183 able to grab ownership of the lock. There is no return value in this
184 case.
185
186 When invoked with the blocking argument set to true, do the same thing
187 as when called without arguments, and return true.
188
189 When invoked with the blocking argument set to false, do not block. If a
190 call without an argument would block, return false immediately;
191 otherwise, do the same thing as when called without arguments, and
192 return true.
193
194 When invoked with the floating-point timeout argument set to a positive
195 value, block for at most the number of seconds specified by timeout
196 and as long as the lock cannot be acquired. Return true if the lock has
197 been acquired, false if the timeout has elapsed.
198
199 """
200 me = get_ident()
201 if self._owner == me:
202 self._count += 1
203 return 1
204 rc = self._block.acquire(blocking, timeout)
205 if rc:
206 self._owner = me
207 self._count = 1
208 return rc
209
210 __enter__ = acquire
211

Callers 9

_acquire_restoreMethod · 0.45
_acquire_restoreMethod · 0.45
_is_ownedMethod · 0.45
waitMethod · 0.45
_internal_pollMethod · 0.45
_waitMethod · 0.45
_get_candidate_namesFunction · 0.45
_gettempdirFunction · 0.45
getMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected