@@ -36,11 +36,6 @@ This module defines the following constants and functions: |
36 | 36 | This is now a synonym of the built-in :exc:`RuntimeError`. |
37 | 37 |
|
38 | 38 |
|
39 | | -.. data:: LockType |
40 | | - |
41 | | - This is the type of lock objects. |
42 | | - |
43 | | - |
44 | 39 | .. function:: start_new_thread(function, args[, kwargs]) |
45 | 40 |
|
46 | 41 | Start a new thread and return its identifier. The thread executes the |
@@ -159,58 +154,66 @@ This module defines the following constants and functions: |
159 | 154 | .. versionadded:: 3.2 |
160 | 155 |
|
161 | 156 |
|
162 | | -Lock objects have the following methods: |
| 157 | +.. raw:: html |
| 158 | + |
| 159 | + <!-- Keep the old URL fragments working (see gh-89554) --> |
| 160 | + <span id='thread.lock.acquire'></span> |
| 161 | + <span id='thread.lock.release'></span> |
| 162 | + <span id='thread.lock.locked'></span> |
163 | 163 |
|
| 164 | +.. class:: LockType |
164 | 165 |
|
165 | | -.. method:: lock.acquire(blocking=True, timeout=-1) |
| 166 | + This is the type of lock objects. |
166 | 167 |
|
167 | | - Without any optional argument, this method acquires the lock unconditionally, if |
168 | | - necessary waiting until it is released by another thread (only one thread at a |
169 | | - time can acquire a lock --- that's their reason for existence). |
| 168 | + Lock objects have the following methods: |
170 | 169 |
|
171 | | - If the *blocking* argument is present, the action depends on its |
172 | | - value: if it is false, the lock is only acquired if it can be acquired |
173 | | - immediately without waiting, while if it is true, the lock is acquired |
174 | | - unconditionally as above. |
| 170 | + .. method:: acquire(blocking=True, timeout=-1) |
175 | 171 |
|
176 | | - If the floating-point *timeout* argument is present and positive, it |
177 | | - specifies the maximum wait time in seconds before returning. A negative |
178 | | - *timeout* argument specifies an unbounded wait. You cannot specify |
179 | | - a *timeout* if *blocking* is false. |
| 172 | + Without any optional argument, this method acquires the lock unconditionally, if |
| 173 | + necessary waiting until it is released by another thread (only one thread at a |
| 174 | + time can acquire a lock --- that's their reason for existence). |
180 | 175 |
|
181 | | - The return value is ``True`` if the lock is acquired successfully, |
182 | | - ``False`` if not. |
| 176 | + If the *blocking* argument is present, the action depends on its |
| 177 | + value: if it is false, the lock is only acquired if it can be acquired |
| 178 | + immediately without waiting, while if it is true, the lock is acquired |
| 179 | + unconditionally as above. |
183 | 180 |
|
184 | | - .. versionchanged:: 3.2 |
185 | | - The *timeout* parameter is new. |
| 181 | + If the floating-point *timeout* argument is present and positive, it |
| 182 | + specifies the maximum wait time in seconds before returning. A negative |
| 183 | + *timeout* argument specifies an unbounded wait. You cannot specify |
| 184 | + a *timeout* if *blocking* is false. |
186 | 185 |
|
187 | | - .. versionchanged:: 3.2 |
188 | | - Lock acquires can now be interrupted by signals on POSIX. |
| 186 | + The return value is ``True`` if the lock is acquired successfully, |
| 187 | + ``False`` if not. |
189 | 188 |
|
190 | | - .. versionchanged:: 3.14 |
191 | | - Lock acquires can now be interrupted by signals on Windows. |
| 189 | + .. versionchanged:: 3.2 |
| 190 | + The *timeout* parameter is new. |
192 | 191 |
|
| 192 | + .. versionchanged:: 3.2 |
| 193 | + Lock acquires can now be interrupted by signals on POSIX. |
193 | 194 |
|
194 | | -.. method:: lock.release() |
| 195 | + .. versionchanged:: 3.14 |
| 196 | + Lock acquires can now be interrupted by signals on Windows. |
195 | 197 |
|
196 | | - Releases the lock. The lock must have been acquired earlier, but not |
197 | | - necessarily by the same thread. |
| 198 | + .. method:: release() |
198 | 199 |
|
| 200 | + Releases the lock. The lock must have been acquired earlier, but not |
| 201 | + necessarily by the same thread. |
199 | 202 |
|
200 | | -.. method:: lock.locked() |
| 203 | + .. method:: locked() |
201 | 204 |
|
202 | | - Return the status of the lock: ``True`` if it has been acquired by some thread, |
203 | | - ``False`` if not. |
| 205 | + Return the status of the lock: ``True`` if it has been acquired by some thread, |
| 206 | + ``False`` if not. |
204 | 207 |
|
205 | | -In addition to these methods, lock objects can also be used via the |
206 | | -:keyword:`with` statement, e.g.:: |
| 208 | + In addition to these methods, lock objects can also be used via the |
| 209 | + :keyword:`with` statement, e.g.:: |
207 | 210 |
|
208 | | - import _thread |
| 211 | + import _thread |
209 | 212 |
|
210 | | - a_lock = _thread.allocate_lock() |
| 213 | + a_lock = _thread.allocate_lock() |
211 | 214 |
|
212 | | - with a_lock: |
213 | | - print("a_lock is locked while this executes") |
| 215 | + with a_lock: |
| 216 | + print("a_lock is locked while this executes") |
214 | 217 |
|
215 | 218 | **Caveats:** |
216 | 219 |
|
|