fixed race conditions on hid events cleanup

This commit is contained in:
Devaev Maxim 2020-08-18 10:57:02 +03:00
parent 28cc3fe99a
commit 6c35dd413d
2 changed files with 8 additions and 2 deletions

View File

@ -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:

View File

@ -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: