Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PyQt: QMutexLocker not released on exception
- def query(self,query):
- lock = QMutexLocker(self.mutex)
- reply = self.conn.query(query)
- if (re.search("error", reply) != None):
- raise GeneralError("Query error")
- #more code...
- return reply
- def query(self, query):
- lock = QMutexLocker(self.mutex)
- reply = self.conn.query(query)
- if re.search("error", reply):
- lock.unlock()
- raise GeneralError("Query error")
- from PyQt4.QtCore import QMutex, QMutexLocker
- def bad_lock(aLock):
- locker = QMutexLocker(aLock)
- print "Locked"
- raise RuntimeError("Test exception")
- return "Should not get here"
- def good_lock(aLock):
- with QMutexLocker(aLock):
- print "Locked"
- raise RuntimeError("Test exception")
- return "Should not get here"
- lock = QMutex()
- bad_lock(lock)
- print lock.tryLock()
- # False
- lock.unlock()
- good_lock(lock)
- print lock.tryLock()
- # True
- def good_lock(aLock):
- # do a bunch of stuff here
- ...
- # critical section
- with QMutexLocker(aLock):
- # do critical stuff here
- ...
- # do other stuff here
- ...
- return True
Add Comment
Please, Sign In to add comment