Skip to content

Commit

Permalink
rougeth#175: Trying to improve Bottery.stop once again.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivkalita committed Oct 24, 2018
1 parent 4ddefff commit 2e557c1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 10 additions & 2 deletions bottery/bottery.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,16 @@ def run(self, server_port):
# sys.exit(1)

click.echo('Quit the bot with CONTROL-C')
self.loop.run_forever()

try:
self.loop.run_forever()
except KeyboardInterrupt:
self.stop()
finally:
self.cleanup()

def stop(self):
asyncio.gather(self.session.close())
self.loop.stop()

def cleanup(self):
self.loop.run_until_complete(self.session.close())
6 changes: 1 addition & 5 deletions bottery/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,4 @@ def import_string(import_name):
@click.option('--port', default=7000, type=int)
def run(bot_module, port):
bot = Bottery()

try:
bot.run(server_port=port)
except KeyboardInterrupt:
bot.stop()
bot.run(server_port=port)

0 comments on commit 2e557c1

Please sign in to comment.