save_variables: Use threaded io

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
This commit is contained in:
Timofey Titovets authored and KevinOConnor committed 2026-07-30 20:59:55 -04:00
1 parent cb02056659
commit 332fbf2363
1 file changed
+7 -4
+7 -4
View File
@@ -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)