summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-10-13 17:27:36 +0300
committerDevaev Maxim <[email protected]>2020-10-13 17:27:36 +0300
commitbee33f2df629a702dd61345e14d807720b94e3e9 (patch)
tree1b363681425cf7c7d1665c511e55821c8f2bfb9f /kvmd
parent23ff97ba95e75f25018bafd076e4f76cbbb598f9 (diff)
tools.clear_queue()
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/plugins/hid/otg/device.py7
-rw-r--r--kvmd/plugins/hid/serial.py7
-rw-r--r--kvmd/tools.py11
3 files changed, 15 insertions, 10 deletions
diff --git a/kvmd/plugins/hid/otg/device.py b/kvmd/plugins/hid/otg/device.py
index bead6d59..3fad9d3c 100644
--- a/kvmd/plugins/hid/otg/device.py
+++ b/kvmd/plugins/hid/otg/device.py
@@ -31,6 +31,7 @@ from typing import Dict
from ....logging import get_logger
+from .... import tools
from .... import aiomulti
from .... import aioproc
@@ -134,11 +135,7 @@ class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-in
self.__events_queue.put_nowait(event)
def _clear_queue(self) -> None:
- while not self.__events_queue.empty():
- try:
- self.__events_queue.get_nowait()
- except queue.Empty:
- break
+ tools.clear_queue(self.__events_queue)
def _ensure_write(self, report: bytes, reopen: bool=False, close: bool=False) -> bool:
if reopen:
diff --git a/kvmd/plugins/hid/serial.py b/kvmd/plugins/hid/serial.py
index 1019bdd4..e1a85b1a 100644
--- a/kvmd/plugins/hid/serial.py
+++ b/kvmd/plugins/hid/serial.py
@@ -43,6 +43,7 @@ from ...logging import get_logger
from ...keyboard.mappings import KEYMAP
from ... import env
+from ... import tools
from ... import aiotools
from ... import aiomulti
from ... import aioproc
@@ -320,11 +321,7 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
self.__queue_event(_MouseWheelEvent(delta_x, delta_y))
def clear_events(self) -> None:
- while not self.__events_queue.empty():
- try:
- self.__events_queue.get_nowait()
- except queue.Empty:
- break
+ tools.clear_queue(self.__events_queue)
self.__queue_event(_ClearEvent())
def __queue_event(self, event: _BaseEvent) -> None:
diff --git a/kvmd/tools.py b/kvmd/tools.py
index 6d10e227..555ddc3e 100644
--- a/kvmd/tools.py
+++ b/kvmd/tools.py
@@ -22,6 +22,8 @@
import operator
import functools
+import multiprocessing.queues
+import queue
from typing import Tuple
from typing import List
@@ -53,3 +55,12 @@ _DictValueT = TypeVar("_DictValueT")
def sorted_kvs(dct: Dict[_DictKeyT, _DictValueT]) -> List[Tuple[_DictKeyT, _DictValueT]]:
return sorted(dct.items(), key=operator.itemgetter(0))
+
+
+# =====
+def clear_queue(q: multiprocessing.queues.Queue) -> None: # pylint: disable=invalid-name
+ for _ in range(q.qsize()):
+ try:
+ q.get_nowait()
+ except queue.Empty:
+ break