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