class threading.Lock
The class implementing primitive lock objects. Once a thread has acquired a lock, subsequent attempts to acquire it block, until it is released; any thread may release it.
Changed in version 3.3: Changed from a factory function to a class.
-
acquire(blocking=True, timeout=-1)
-
Acquire a lock, blocking or non-blocking.
When invoked with the blocking argument set to
True
(the default), block until the lock is unlocked, then set it to locked and returnTrue
.When invoked with the blocking argument set to
False
, do not block. If a call with blocking set toTrue
would block, returnFalse
immediately; otherwise, set the lock to locked and returnTrue
.When invoked with the floating-point timeout argument set to a positive value, block for at most the number of seconds specified by timeout and as long as the lock cannot be acquired. A timeout argument of
-1
specifies an unbounded wait. It is forbidden to specify a timeout when blocking is false.The return value is
True
if the lock is acquired successfully,False
if not (for example if the timeout expired).Changed in version 3.2: The timeout parameter is new.
Changed in version 3.2: Lock acquires can now be interrupted by signals on POSIX.
-
release()
-
Release a lock. This can be called from any thread, not only the thread which has acquired the lock.
When the lock is locked, reset it to unlocked, and return. If any other threads are blocked waiting for the lock to become unlocked, allow exactly one of them to proceed.
When invoked on an unlocked lock, a
RuntimeError
is raised.There is no return value.
Please login to continue.