diff options
author | Devaev Maxim <[email protected]> | 2020-10-13 17:27:36 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2020-10-13 17:27:36 +0300 |
commit | bee33f2df629a702dd61345e14d807720b94e3e9 (patch) | |
tree | 1b363681425cf7c7d1665c511e55821c8f2bfb9f /kvmd/tools.py | |
parent | 23ff97ba95e75f25018bafd076e4f76cbbb598f9 (diff) |
tools.clear_queue()
Diffstat (limited to 'kvmd/tools.py')
-rw-r--r-- | kvmd/tools.py | 11 |
1 files changed, 11 insertions, 0 deletions
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 |