Skip to content

Commit 38bbf29

Browse files
committed
Protect queue.get() with timeout
1 parent f0825a1 commit 38bbf29

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

plugwise_usb/connection/queue.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33
from __future__ import annotations
44

5-
from asyncio import PriorityQueue, Task, get_running_loop, sleep
5+
from asyncio import (
6+
PriorityQueue,
7+
Task,
8+
TimeoutError,
9+
get_running_loop,
10+
sleep,
11+
wait_for,
12+
)
613
from collections.abc import Callable
714
from dataclasses import dataclass
815
import logging
@@ -138,7 +145,11 @@ async def _send_queue_worker(self) -> None:
138145
"""Send messages from queue at the order of priority."""
139146
_LOGGER.debug("Send_queue_worker started")
140147
while self._running and self._stick is not None:
141-
request = await self._submit_queue.get()
148+
try:
149+
request = await wait_for(self._submit_queue.get(), timeout = 0.5)
150+
except TimeoutError:
151+
_LOGGER.debug("No queue-item after 0.5s, doing other work")
152+
142153
_LOGGER.debug("Sending from send queue %s", request)
143154
if request.priority == Priority.CANCEL:
144155
self._submit_queue.task_done()

0 commit comments

Comments
 (0)