Close database on sigterm

This commit is contained in:
Ceda EI 2018-11-05 15:30:36 +05:30
parent 83ced1b9a0
commit 4c5b3de556
1 changed files with 9 additions and 0 deletions

9
bot.py
View File

@ -7,6 +7,8 @@ import questable
import random import random
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, \ from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, \
RegexHandler RegexHandler
import signal
import sys
try: try:
import config import config
@ -456,8 +458,15 @@ def message_handling(bot, update, db):
edit_quest(bot, update, player, state["extra"], "diff", "side_quest") edit_quest(bot, update, player, state["extra"], "diff", "side_quest")
def sigterm_handler(signal, frame, db):
db.close()
sys.exit(0)
db = sqlite3.connect("questable.db", check_same_thread=False) db = sqlite3.connect("questable.db", check_same_thread=False)
cursor = db.cursor() cursor = db.cursor()
signal.signal(signal.SIGTERM, lambda x, y: sigterm_handler(x, y, db))
# Set up tables # Set up tables
queries = [ queries = [
("CREATE TABLE IF NOT EXISTS quests(chat_id int NOT NULL, qid int NOT" ("CREATE TABLE IF NOT EXISTS quests(chat_id int NOT NULL, qid int NOT"