I have Managed to build a web hosting platform using django i intend to make the platform free webhosting platform but the problem i have is that my django server needs to reload from time to time .i have tried the following options bellow.
import time
import schedule
import keyboard
from threading import *
from datetime import datetime
import django
from django.utils import autoreload
class ExitCommand(Exception):
pass
def load():
try:
django.setup()
keyboard.press_and_release("Ctrl+c")
autoreload.autoreload_started
autoreload.DJANGO_AUTORELOAD_ENV
autoreload.file_changed
run=autoreload.StatReloader()
run.should_stop=False
run.run_loop()
print("Server changes detected")
now=autoreload.get_reloader()
now.notify_file_changed(os.path.join(BASE_DIR))
raise ExitCommand()
except ExitCommand:
keyboard.press_and_release("Ctrl+s")
# autoreload.autoreload_started
# autoreload.get_reloader()
# autoreload.DJANGO_AUTORELOAD_ENV
# autoreload.raise_last_exception()
# autoreload.iter_all_python_module_files()
# autoreload.restart_with_reloader()
os.system("python manage.py runserver 8080")
print("++Reloading Server+++")
def relaod_server():
load_time="22:59:00"
now=datetime.now()
current_time=now.strftime("%H:%M:%S")
start_time=datetime.strptime(load_time,"%H:%M:%S")
stop_time=datetime.strptime(current_time,"%H:%M:%S")
time_diffrence=start_time-stop_time
os.environ["RELOAD_HOURS_REMAINING"]=str(time_diffrence)
schedule.every().day.at("23:47").do(load)
while True:
schedule.run_pending()
time.sleep(1)
refresh=Thread(target=relaod_server,args=[])
refresh.setDaemon(True)
refresh.start()
`your text`
What am trying to do is to make django server reload automatically after some time kindly help,i am working on my company start up.i am working on a webhosting paltform which i have finished writing the only challange i have is that my django server needs to reload and i dont know how to do that.