ezcoo sw41ha as gpio

This commit is contained in:
Devaev Maxim
2020-10-23 03:33:57 +03:00
parent 4a211ffc10
commit ad943811f9
2 changed files with 223 additions and 10 deletions

View File

@@ -23,11 +23,40 @@
import multiprocessing
import queue
from typing import Tuple
from typing import Dict
from typing import TypeVar
from typing import Optional
from . import aiotools
# =====
_QueueItemT = TypeVar("_QueueItemT")
async def queue_get_last( # pylint: disable=invalid-name
q: "multiprocessing.Queue[_QueueItemT]",
timeout: float,
) -> Tuple[bool, Optional[_QueueItemT]]:
return (await aiotools.run_async(queue_get_last_sync, q, timeout))
def queue_get_last_sync( # pylint: disable=invalid-name
q: "multiprocessing.Queue[_QueueItemT]",
timeout: float,
) -> Tuple[bool, Optional[_QueueItemT]]:
try:
item = q.get(timeout=timeout)
while not q.empty():
item = q.get()
return (True, item)
except queue.Empty:
return (False, None)
# =====
class AioProcessNotifier:
def __init__(self) -> None:
@@ -37,18 +66,9 @@ class AioProcessNotifier:
self.__queue.put_nowait(None)
async def wait(self) -> None:
while not (await aiotools.run_async(self.__inner_wait)):
while not (await queue_get_last(self.__queue, 0.1))[0]:
pass
def __inner_wait(self) -> bool:
try:
self.__queue.get(timeout=0.1)
while not self.__queue.empty():
self.__queue.get()
return True
except queue.Empty:
return False
# =====
class AioSharedFlags: