The thread Module
The only part of the thread
module that your code should use directly is the lock objects that module thread
supplies. Locks are simple thread-synchronization primitives. Technically, thread
’s locks are non-reentrant and unowned: they do not keep track of which thread last locked them, so there is no specific owner thread for a lock. A lock is in one of two states, locked or unlocked.
To get a new lock object (in the unlocked state), call the factory function named allocate_lock
without arguments. This function is supplied by both modules thread
and threading
. A lock object L
supplies three methods.
acquire |
When |
locked |
Returns |
release |
Unlocks |
Get Python in a Nutshell, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.