def awake_mysql_db(): """" If there's no connection, creates one, else pings to wake up the connection """ global db if db is None: db = constants.initialize_mysql() else: db.ping(True)
block of code. It uses threading to do the job. So if you don't have the opportunity to execute the scheduled_task.py script you can use this code. """ import constants import datetime import telebot import flask from flask import Flask from flask_sslify import SSLify # Initialization app = Flask(__name__) sslify = SSLify(app) bot = telebot.TeleBot(constants.bot_token, threaded=False) db = constants.initialize_mysql() cursor = db.cursor() def awake_mysql_db(): """" If there's no connection, creates one, else pings to wake up the connection """ global db if db is None: db = constants.initialize_mysql() else: db.ping(True) # -----------------------------------------