在第一篇文章中,主要学习了一些概念性的东东,这里还是想把threading提供的实例用法好好琢磨一下,方便以后使用的时候能够正确理解并运用这些方法。
threading模块中Thread类实例提供的方法及用途上一篇基本上说清楚了,接着往下看看其它实例
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.
Note that Lock is actually a factory function which returns an instance of the most efficient version of the concrete Lock class that is supported by the platform.
acquire(blocking=True, timeout=-1)
Acquire a lock, blocking or non-blocking.
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 r