How to execute function in an interval?

1

I am trying to execute a function in the background every 5 seconds in which I check the data of an object and modify it.

I have found this form (see code) but I can not get it to run when I deploy the Django server.

Code

import threading

def hilo_promo(f_stop):
    print('se ejecuta hilo')
    promocion = Promocion.objects.get(id=1)
    if promocion.fecha_fin.strftime('%Y-%m-%d %H:%M:%S') <= hoy and promocion.activo == True:
        promocion.activo = False
        promocion.save()
    if not f_stop.is_set():
        threading.Timer(5, hilo_promo, [f_stop]).start()
    print(promocion.activo)

f_stop = threading.Event()
hilo_promo(f_stop)
    
asked by F Delgado 20.07.2018 в 10:18
source

0 answers