From 00f06b5d85fd8db75e499f3fa68568f35f40e09b Mon Sep 17 00:00:00 2001 From: stalbe_j Date: Mon, 17 Apr 2023 13:48:19 +0200 Subject: [PATCH] add commandbuffer --- grum/cmdbuf.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 grum/cmdbuf.py diff --git a/grum/cmdbuf.py b/grum/cmdbuf.py new file mode 100644 index 0000000..86a8d3a --- /dev/null +++ b/grum/cmdbuf.py @@ -0,0 +1,34 @@ +from queue import Queue +from threading import Thread + + +class CommandBuffer: + + def __init__(self): + self.cmds = Queue() + self.thread = None + self.running = False + + def _run(self): + self.running = True + while self.running: + c = self.cmds.get() + func, args, kwargs = c + print("run:", func, args, kwargs.keys()) + func(*args, **kwargs) + + def start(self): + self.thread = thread = Thread(target=self._run) + thread.start() + + def stop(self): + self.running = False + + def add(self, func, *args, **kwargs): + print("add:", func, args, kwargs.keys()) + c = (func, args, kwargs) + self.cmds.put(c) + + + +