From ff7cc3f8f346aee1a7a3538e592b6757feee61a4 Mon Sep 17 00:00:00 2001 From: Chris Bras Date: Thu, 7 Mar 2019 23:14:48 +0100 Subject: [PATCH] interrupts zijn eleganter nu ReeEEeeeEEE :lenny: hoe lang kan ik dit eigenlijk maken ik heb dat nog nooit echt geprobeerd --- malaria.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/malaria.py b/malaria.py index 010bdde..c533453 100644 --- a/malaria.py +++ b/malaria.py @@ -228,12 +228,16 @@ class Model: This functions runs the simulation """ print(chr(27) + "[2J") - for t in range(self.time_steps): - print("Simulating timestep: {}".format(t), end='\r') - self.step() - if self.graphical: - self.draw(t) - + # actual simulation runs inside try except to catch keyboard interrupts and always print stats + try: + for t in range(self.time_steps): + print("Simulating timestep: {}".format(t), end='\r') + self.step() + if self.graphical: + self.draw(t) + except KeyboardInterrupt: + pass + print(chr(27) + "[2J") self.compile_stats() self.print_stats() @@ -315,6 +319,6 @@ class Human(IntEnum): if __name__ == "__main__": - model = Model(graphical=False) + model = Model(graphical=True) model.run()