Files
py_luggage/main.py
T

51 lines
1.1 KiB
Python

import logging
import subprocess
import sys
import os
import api_security as auth
import time
try:
os.remove("api.log")
os.remove("api_server.log")
os.remove("app.log")
except Exception as e:
logging.error(e)
#Logging
logging.basicConfig(
filename='app.log', # Log to a file
level=logging.DEBUG, # Log everything (DEBUG and above)
format='%(asctime)s %(levelname)s %(message)s'
)
logging.info('Application started')
try:
logging.debug('Debug info here')
except Exception as e:
logging.exception('An error occurred')
env = os.environ.copy()
env["PYTHONIOENCODING"] = "utf-8"
log_file = open("api_server.log", "w", encoding="utf-8")
api_process = subprocess.Popen(
["fastapi", "dev", "api_server.py"],
stdout=log_file,
stderr=log_file,
env=env
)
cli_process = subprocess.Popen([sys.executable, "cli.py"])
api_process.wait()
cli_process.wait()
# automatic durataion validation check
while True:
time.sleep(300)
try:
auth.check_validaty()
except Exception as e:
logging.info(e)