<div><h4id="or-1">Or:</h4><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">with</span><lock>: <spanclass="hljs-comment"># Enters the block by calling acquire(),</span>
... <spanclass="hljs-comment"># and exits it with release().</span>
... <spanclass="hljs-comment"># and exits it with release(), even on error.</span>
</code></pre></div>
<div><h3id="semaphoreeventbarrier">Semaphore, Event, Barrier</h3><pre><codeclass="python language-python hljs"><Semaphore> = Semaphore(value=<spanclass="hljs-number">1</span>) <spanclass="hljs-comment"># Lock that can be acquired by 'value' threads.</span>