Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored SIGINT handler so it catches SIGINT during relog loop #3867

Merged
merged 3 commits into from
Aug 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down