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 json import dump as jdump, load as jload
from os import makedirs, remove
from os.path import exists, dirname
from os.path import dirname, exists
from select import select as timedInput
from sys import stdin
from yaml import safe_load

View File

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

View File

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