diff options
| author | Paul Oliver <contact@pauloliver.dev> | 2024-02-29 02:29:14 +0100 | 
|---|---|---|
| committer | Paul Oliver <contact@pauloliver.dev> | 2024-02-29 02:29:14 +0100 | 
| commit | de427d319c699b8bed7ed73289b3698f13ac3acc (patch) | |
| tree | 8ed7bf17bc45480589f39cff60a3258c6aad39cb /bin/handler.py | |
| parent | 8bef0b04edd10fe15589ae97edee5af177c635e0 (diff) | |
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.
Diffstat (limited to 'bin/handler.py')
| -rw-r--r-- | bin/handler.py | 12 | 
1 files changed, 10 insertions, 2 deletions
| 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 | 
