| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 025cc26 commit e37ce56
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -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 | |
@@ -162,58 +157,66 @@ This module defines the following constants and functions: | |||
| 162 | 157 | .. versionadded:: 3.2 | |
| 163 | 158 | ||
| 164 | 159 | ||
| 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> | ||
| 166 | 166 | ||
| 167 | + .. class:: LockType | ||
| 167 | 168 | ||
| 168 | - .. method:: lock.acquire(blocking=True, timeout=-1) | ||
| 169 | + This is the type of lock objects. | ||
| 169 | 170 | ||
| 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: | ||
| 173 | 172 | ||
| 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) | ||
| 178 | 174 | ||
| 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). | ||
| 183 | 178 | ||
| 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. | ||
| 186 | 183 | ||
| 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. | ||
| 189 | 188 | ||
| 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. | ||
| 192 | 191 | ||
| 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. | ||
| 195 | 194 | ||
| 195 | + .. versionchanged:: 3.2 | ||
| 196 | + Lock acquires can now be interrupted by signals on POSIX. | ||
| 196 | 197 | ||
| 197 | - .. method:: lock.release() | ||
| 198 | + .. versionchanged:: 3.14 | ||
| 199 | + Lock acquires can now be interrupted by signals on Windows. | ||
| 198 | 200 | ||
| 199 | - Releases the lock. The lock must have been acquired earlier, but not | ||
| 200 | - necessarily by the same thread. | ||
| 201 | + .. method:: release() | ||
| 201 | 202 | ||
| 203 | + Releases the lock. The lock must have been acquired earlier, but not | ||
| 204 | + necessarily by the same thread. | ||
| 202 | 205 | ||
| 203 | - .. method:: lock.locked() | ||
| 206 | + .. method:: locked() | ||
| 204 | 207 | ||
| 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. | ||
| 207 | 210 | ||
| 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.:: | ||
| 210 | 213 | ||
| 211 | - import _thread | ||
| 214 | + import _thread | ||
| 212 | 215 | ||
| 213 | - a_lock = _thread.allocate_lock() | ||
| 216 | + a_lock = _thread.allocate_lock() | ||
| 214 | 217 | ||
| 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") | ||
| 217 | 220 | ||
| 218 | 221 | **Caveats:** | |
| 219 | 222 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments