def test_lock_error(self): lock = ReadWriteLock() py.test.raises(LockingError, lock.release_read) py.test.raises(LockingError, lock.release_write) py.test.raises(LockingError, lock.upgrade) py.test.raises(LockingError, lock.downgrade) lock.acquire_read() py.test.raises(LockingError, lock.release_write) lock.upgrade() py.test.raises(LockingError, lock.release_read) lock.release_write()
from draco2.core.event import EventManager from draco2.core.handler import Handler from draco2.draco.handler import DracoHandler from draco2.database.manager import DatabaseManager from draco2.model.manager import ModelManager from draco2.security.context import SecurityContext from draco2.email.sendmail import Sendmail from draco2.util import http from draco2.util import uri as urimod from draco2.util.rwlock import ReadWriteLock from draco2.util.singleton import singleton from draco2.util.misc import get_backtrace initialized = False rwlock = ReadWriteLock() initlock = threading.Lock() def handle_request(iface): """Handle a request.""" # Acquire the read-write lock. This lock is held by all threads in # read mode when serving a Draco request. If one of the global Draco # objects needs to be reloaded, the lock is upgraded to write mode # by the thread that detected the reload condition. All threads will # then serialize and the reload can continue. rwlock.acquire_read() try: # Once off initialization. No user code can be run from this, and # there's no option of recording errors. initlock.acquire()