Guest User

Untitled

a guest
Sep 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. PyQt: QMutexLocker not released on exception
  2. def query(self,query):
  3. lock = QMutexLocker(self.mutex)
  4. reply = self.conn.query(query)
  5. if (re.search("error", reply) != None):
  6. raise GeneralError("Query error")
  7.  
  8. #more code...
  9. return reply
  10.  
  11. def query(self, query):
  12. lock = QMutexLocker(self.mutex)
  13. reply = self.conn.query(query)
  14. if re.search("error", reply):
  15. lock.unlock()
  16. raise GeneralError("Query error")
  17.  
  18. from PyQt4.QtCore import QMutex, QMutexLocker
  19.  
  20. def bad_lock(aLock):
  21. locker = QMutexLocker(aLock)
  22. print "Locked"
  23. raise RuntimeError("Test exception")
  24.  
  25. return "Should not get here"
  26.  
  27. def good_lock(aLock):
  28. with QMutexLocker(aLock):
  29. print "Locked"
  30. raise RuntimeError("Test exception")
  31.  
  32. return "Should not get here"
  33.  
  34. lock = QMutex()
  35.  
  36. bad_lock(lock)
  37. print lock.tryLock()
  38. # False
  39.  
  40. lock.unlock()
  41.  
  42. good_lock(lock)
  43. print lock.tryLock()
  44. # True
  45.  
  46. def good_lock(aLock):
  47.  
  48. # do a bunch of stuff here
  49. ...
  50.  
  51. # critical section
  52. with QMutexLocker(aLock):
  53. # do critical stuff here
  54. ...
  55.  
  56. # do other stuff here
  57. ...
  58.  
  59. return True
Add Comment
Please, Sign In to add comment