fix: catch closed connection

This commit is contained in:
Lunaresk 2021-12-28 14:50:25 +01:00
parent d297fa2cef
commit 0768bb4ecf
3 changed files with 14 additions and 10 deletions

View File

@ -3,7 +3,7 @@ from copy import deepcopy
from datetime import date from datetime import date
from json import dump as jdump, load as jload from json import dump as jdump, load as jload
from os import makedirs, remove from os import makedirs, remove
from os.path import exists, dirname from os.path import dirname, exists
from select import select as timedInput from select import select as timedInput
from sys import stdin from sys import stdin
from yaml import safe_load from yaml import safe_load

View File

@ -43,14 +43,18 @@ class Database:
LOGGER.info("Connection was not set, setting...") LOGGER.info("Connection was not set, setting...")
self.connect() self.connect()
else: else:
with self.conn.cursor() as cursor: try:
try: with self.conn.cursor() as cursor:
cursor.execute("SELECT 1;") try:
cursor.fetchall() cursor.execute("SELECT 1;")
except: cursor.fetchall()
LOGGER.warn( except:
'Connection seem to timed out, reconnecting...') LOGGER.warn(
self.connect() 'Connection seem to timed out, reconnecting...')
self.connect()
except:
LOGGER.warn('Connection seem to timed out, reconnecting...')
self.connect()
def connectionpersistence(func): def connectionpersistence(func):
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):

View File

@ -3,7 +3,7 @@ from flask import Flask, abort, request
from flask.json import jsonify from flask.json import jsonify
from gevent.pywsgi import WSGIServer from gevent.pywsgi import WSGIServer
from os import makedirs from os import makedirs
from os.path import exists, dirname from os.path import dirname, exists
import logging import logging