MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / acquire

Method acquire

tools/python-3.11.9-amd64/Lib/asyncio/locks.py:93–123  ·  view source on GitHub ↗

Acquire a lock. This method blocks until the lock is unlocked, then sets it to locked and returns True.

(self)

Source from the content-addressed store, hash-verified

91 return self._locked
92
93 async def acquire(self):
94 """Acquire a lock.
95
96 This method blocks until the lock is unlocked, then sets it to
97 locked and returns True.
98 """
99 if (not self._locked and (self._waiters is None or
100 all(w.cancelled() for w in self._waiters))):
101 self._locked = True
102 return True
103
104 if self._waiters is None:
105 self._waiters = collections.deque()
106 fut = self._get_loop().create_future()
107 self._waiters.append(fut)
108
109 # Finally block should be called before the CancelledError
110 # handling as we don't want CancelledError to call
111 # _wake_up_first() and attempt to wake up itself.
112 try:
113 try:
114 await fut
115 finally:
116 self._waiters.remove(fut)
117 except exceptions.CancelledError:
118 if not self._locked:
119 self._wake_up_first()
120 raise
121
122 self._locked = True
123 return True
124
125 def release(self):
126 """Release a lock.

Callers 12

__aenter__Method · 0.45
waitMethod · 0.45
add_cookie_headerMethod · 0.45
set_cookie_if_okMethod · 0.45
set_cookieMethod · 0.45
extract_cookiesMethod · 0.45
clear_session_cookiesMethod · 0.45
clear_expired_cookiesMethod · 0.45
revertMethod · 0.45
__enter__Method · 0.45
_adjust_thread_countMethod · 0.45
_adjust_process_countMethod · 0.45

Calls 6

_wake_up_firstMethod · 0.95
_get_loopMethod · 0.80
cancelledMethod · 0.45
create_futureMethod · 0.45
appendMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected