diff --git a/pokecli.py b/pokecli.py index 064c87c9ba..1c07365adf 100644 --- a/pokecli.py +++ b/pokecli.py @@ -64,11 +64,11 @@ class SIGINTRecieved(Exception): pass def main(): bot = False - try: - def handle_sigint(*args): - raise SIGINTRecieved - signal.signal(signal.SIGINT, handle_sigint) + def handle_sigint(*args): + raise SIGINTRecieved + signal.signal(signal.SIGINT, handle_sigint) + try: logger.info('PokemonGO Bot v1.0') sys.stdout = codecs.getwriter('utf8')(sys.stdout) sys.stderr = codecs.getwriter('utf8')(sys.stderr) @@ -102,7 +102,7 @@ def handle_sigint(*args): while True: bot.tick() - except (KeyboardInterrupt, SIGINTRecieved): + except KeyboardInterrupt: bot.event_manager.emit( 'bot_exit', sender=bot, @@ -139,6 +139,15 @@ def handle_sigint(*args): except GeocoderQuotaExceeded: raise Exception("Google Maps API key over requests limit.") + except SIGINTRecieved: + if bot: + bot.event_manager.emit( + 'bot_interrupted', + sender=bot, + level='info', + formatted='Bot caught SIGINT. Shutting down.' + ) + report_summary(bot) except Exception as e: # always report session summary and then raise exception if bot: diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index ff5257c043..27ce65f8e4 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -150,6 +150,7 @@ def _register_events(self): self.event_manager.register_event('bot_start') self.event_manager.register_event('bot_exit') + self.event_manager.register_event('bot_interrupted') # sleep stuff self.event_manager.register_event(