diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-06-07 14:14:46 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-06-08 21:52:45 +0100 |
commit | bd12792f28efd2f03510653ec947ebf961315272 (patch) | |
tree | eb9181fb5bdcef9ac60fd650f650a99a8c6c0bf7 | |
parent | cd7cce4cf4be5c742d29671169354fe84220b47a (diff) | |
download | bitbake-bd12792f28efd2f03510653ec947ebf961315272.tar.gz |
server/process: Avoid risk of exception deadlocks
The open coded lock acquire/release in the UI event handler doesn't
cover the case an exception occurs and if one did, it could deadlock
the code. Switch to use 'with' statements which would handle this
possibility.
We have seen deadlocks in the UI at exit this so this removes a
possible cause.
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | lib/bb/server/process.py | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/lib/bb/server/process.py b/lib/bb/server/process.py index 613956f30..74b74dc39 100644 --- a/lib/bb/server/process.py +++ b/lib/bb/server/process.py @@ -667,18 +667,14 @@ class BBUIEventQueue: self.t.start() def getEvent(self): - self.eventQueueLock.acquire() - - if len(self.eventQueue) == 0: - self.eventQueueLock.release() - return None - - item = self.eventQueue.pop(0) + with self.eventQueueLock: + if len(self.eventQueue) == 0: + return None - if len(self.eventQueue) == 0: - self.eventQueueNotify.clear() + item = self.eventQueue.pop(0) + if len(self.eventQueue) == 0: + self.eventQueueNotify.clear() - self.eventQueueLock.release() return item def waitEvent(self, delay): @@ -686,10 +682,9 @@ class BBUIEventQueue: return self.getEvent() def queue_event(self, event): - self.eventQueueLock.acquire() - self.eventQueue.append(event) - self.eventQueueNotify.set() - self.eventQueueLock.release() + with self.eventQueueLock: + self.eventQueue.append(event) + self.eventQueueNotify.set() def send_event(self, event): self.queue_event(pickle.loads(event)) |