twist_check: survive a closed SSH window and unexpected errors
A closed terminal made print() raise and any unexpected exception skipped the cleanup, leaving the nozzle low and hot. Both now end in the normal stop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
92d86d6bfd
commit
2592030cb4
1 file changed
+15
-3
+15
-3
@@ -91,7 +91,10 @@ class Stopped(Exception):
|
||||
|
||||
def log(text):
|
||||
line = "%s %s" % (time.strftime("%H:%M:%S"), text)
|
||||
try:
|
||||
print(line, flush=True)
|
||||
except OSError:
|
||||
pass # SSH window closed: the run continues, the log file stays
|
||||
if LOG:
|
||||
LOG.write(line + "\n")
|
||||
LOG.flush()
|
||||
@@ -635,16 +638,25 @@ def run(mode, host):
|
||||
failure = ("Twist %s stopped" % mode, [
|
||||
str(e), "Nothing changed in the configuration. "
|
||||
"Fix this, then start again with TWIST_CALIBRATE."])
|
||||
except Exception as e:
|
||||
# Whatever went wrong, the nozzle must still be lifted and switched off
|
||||
failure = ("Twist %s stopped" % mode, [
|
||||
"Unexpected error: %r" % e, "Nothing changed in the configuration."
|
||||
" See twist_data/twist_run.log."])
|
||||
signal.signal(signal.SIGTERM, signal.SIG_IGN)
|
||||
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
||||
if started:
|
||||
cleanup(p)
|
||||
if res:
|
||||
report_console(res)
|
||||
report_html(res, report)
|
||||
try:
|
||||
if res["block"]:
|
||||
with open(os.path.join(DATA_DIR, "twist_suggested.cfg"), "w") as f:
|
||||
with open(os.path.join(DATA_DIR, "twist_suggested.cfg"),
|
||||
"w") as f:
|
||||
f.write(res["block"])
|
||||
report_html(res, report)
|
||||
report_console(res)
|
||||
except Exception as e:
|
||||
log("Could not write the report: %r" % e)
|
||||
log(res["title"])
|
||||
return finish(p, res, failure, os.path.basename(report), started)
|
||||
|
||||
|
||||
Reference in new issue
Block a user