From 6c35dd413dce63d811f996f99adb87e6615a2baf Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Tue, 18 Aug 2020 10:57:02 +0300 Subject: fixed race conditions on hid events cleanup --- kvmd/plugins/hid/otg/device.py | 5 ++++- kvmd/plugins/hid/serial.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'kvmd/plugins/hid') diff --git a/kvmd/plugins/hid/otg/device.py b/kvmd/plugins/hid/otg/device.py index 44c286cb..45681aba 100644 --- a/kvmd/plugins/hid/otg/device.py +++ b/kvmd/plugins/hid/otg/device.py @@ -126,7 +126,10 @@ class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-in def _clear_queue(self) -> None: while not self.__events_queue.empty(): - self.__events_queue.get_nowait() + try: + self.__events_queue.get_nowait() + except queue.Empty: + break 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 752870d7..cee0048d 100644 --- a/kvmd/plugins/hid/serial.py +++ b/kvmd/plugins/hid/serial.py @@ -298,7 +298,10 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst def clear_events(self) -> None: while not self.__events_queue.empty(): - self.__events_queue.get_nowait() + try: + self.__events_queue.get_nowait() + except queue.Empty: + break self.__queue_event(_ClearEvent()) def __queue_event(self, event: _BaseEvent) -> None: -- cgit v1.2.3