Python Library Reference
Previous: Up: 15.3 threading Next:


15.3.8 Using locks, conditions, and semaphores in the with statement

All of the objects provided by this module that have acquire() and release() methods can be used as context managers for a with statement. The acquire() method will be called when the block is entered, and release() will be called when the block is exited.

Currently, Lock, RLock, Condition, Semaphore, and BoundedSemaphore objects may be used as with statement context managers. For example:

from __future__ import with_statement
import threading
some_rlock = threading.RLock()
with some_rlock:
 print "some_rlock is locked while this executes"

Python Library Reference
Previous: Up: 15.3 threading Next:

Release 2.5, documentation updated on 19th September, 2006.
See About this document... for information on suggesting changes.

AltStyle によって変換されたページ (->オリジナル) /