From 332fbf2363ff2bee2762e5dffe59f458fc4c03ff Mon Sep 17 00:00:00 2001 From: Timofey Titovets Date: Sat, 21 Mar 2026 00:11:12 +0100 Subject: [PATCH] save_variables: Use threaded io Signed-off-by: Timofey Titovets --- klippy/extras/save_variables.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/klippy/extras/save_variables.py b/klippy/extras/save_variables.py index 2e405657d..b6d6ac619 100644 --- a/klippy/extras/save_variables.py +++ b/klippy/extras/save_variables.py @@ -11,6 +11,8 @@ class SaveVariables: self.printer = config.get_printer() self.filename = os.path.expanduser(config.get('filename')) self.allVariables = {} + aio = self.printer.load_object(config, 'aio_executor') + self.executor = aio.allocate_executor("save_variables") try: if not os.path.exists(self.filename): open(self.filename, "w").close() @@ -24,7 +26,7 @@ class SaveVariables: allvars = {} varfile = configparser.ConfigParser() try: - varfile.read(self.filename) + self.executor.submit(varfile.read, self.filename) if varfile.has_section('Variables'): for name, val in varfile.items('Variables'): allvars[name] = ast.literal_eval(val) @@ -51,9 +53,10 @@ class SaveVariables: for name, val in sorted(newvars.items()): varfile.set('Variables', name, repr(val)) try: - f = open(self.filename, "w") - varfile.write(f) - f.close() + def write_out(): + with open(self.filename, "w") as f: + varfile.write(f) + self.executor.submit(write_out) except: msg = "Unable to save variable" logging.exception(msg)