Skip to content

Commit 840279a

Browse files
Fix issue with db manager waits (#2390)
1 parent 77d74ce commit 840279a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

apps/predbat/db_manager.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,15 @@ def __init__(self, base, db_days):
2929
self.return_event = threading.Event()
3030

3131
def bridge_event(self, loop):
32-
self.sync_event.wait()
33-
loop.call_soon_threadsafe(self.async_event.set)
32+
"""
33+
This function runs in a separate thread to bridge the event loop and the database manager.
34+
It waits for the sync_event to be set and then sets the async_event to notify the main loop.
35+
This allows the database manager to process commands asynchronously.
36+
"""
37+
while not self.stop_thread:
38+
self.sync_event.wait()
39+
self.sync_event.clear() # Clear the event to allow the loop to continue
40+
loop.call_soon_threadsafe(self.async_event.set)
3441

3542
async def start(self):
3643
"""
@@ -49,6 +56,7 @@ async def start(self):
4956
while not self.stop_thread:
5057
if not self.db_queue:
5158
await self.async_event.wait()
59+
self.async_event.clear()
5260
continue
5361
else:
5462
item = self.db_queue.pop(0)

0 commit comments

Comments
 (0)