Skip to content

Commit

Permalink
Fixed issue when bot does not saved db state to disk on code reload a…
Browse files Browse the repository at this point in the history
…nd Ctrl-C.
  • Loading branch information
svetlyak40wt committed Oct 30, 2012
1 parent 9251d75 commit 5ae7252
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion requirements/base.txt
Expand Up @@ -7,4 +7,4 @@ times==0.6
pytz==2012f
six==1.2.0
PyYAML==3.10
server-reloader==0.1.1
server-reloader==0.1.3
31 changes: 23 additions & 8 deletions scripts/thebot
Expand Up @@ -8,21 +8,36 @@ import sys
import server_reloader

from time import sleep
from contextlib import closing

bot = None


def run_bot(*args):
with closing(thebot.Bot(args)) as bot:
try:
while not bot.exiting:
sleep(1)
except KeyboardInterrupt:
pass
global bot
bot = thebot.Bot(args)

while not bot.exiting:
sleep(1)

bot.close()


def on_reload():
print('Reloading code…')
bot.close()


def on_exit():
print('Exiting…')
bot.close()


def main():
server_reloader.main(
run_bot,
args=tuple(sys.argv[1:]),
before_reload=lambda: print('Reloading code…'),
before_reload=on_reload,
before_exit=on_exit,
watch_on_files=False,
)

Expand Down

0 comments on commit 5ae7252

Please sign in to comment.