From de427d319c699b8bed7ed73289b3698f13ac3acc Mon Sep 17 00:00:00 2001 From: Paul Oliver Date: Thu, 29 Feb 2024 02:29:14 +0100 Subject: Numeric cycle now times out. [#36] Using high numeric keys cycles simulation until a timeout is reached. This helps prevent Salis from hanging if a high number of cycles are requested. --- bin/handler.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'bin/handler.py') diff --git a/bin/handler.py b/bin/handler.py index 40fafea..3325391 100644 --- a/bin/handler.py +++ b/bin/handler.py @@ -20,12 +20,14 @@ console response. This ability gives an user a whole lot of power, and should be used with care. """ -import os import curses +import os +import time class Handler: KEY_ESCAPE = 27 + CYCLE_TIMEOUT = 0.1 def __init__(self, sim): """ Handler constructor. Simply link this class to the main simulation @@ -195,12 +197,18 @@ class Handler: raise RuntimeError(message) def __cycle_sim(self, factor): - """ Simply cycle Salis 'factor' number of times. + """ Simply cycle Salis 'factor' number of times. Do not cycle for more + than a given amount of time. """ + time_max = time.time() + self.CYCLE_TIMEOUT + for _ in range(factor): self.__sim.lib.sal_main_cycle() self.__sim.check_autosave() + if time.time() > time_max: + break + def __get_inst_dict(self): """ Transform the instruction list of the printer module into a dictionary that's more useful for genome compilation. Instruction -- cgit v1.2.1