How to perform a function at the same time in Django?

The task following: to perform the function in views at the same time - say, every day at 12:00.
Found this option with Timer

import datetime as dt

def print_text():
print("Hi!")
next day = dt.datetime.now() + dt.timedelta(days=1)
dateString = next day.strftime('%d-%m-%Y') + "12-00-00"
in the mining = next day.strptime(dateString,'%d-%m-%Y %H-%M-%S')
delay = (in the mining - dt.datetime.now()).total_seconds()
Timer(delay, print_text, ()).start()

But whether it will even continue to count down, if you updated the page, and accordingly, there will be repeated calls to a timer function?
Please help to understand.
June 8th 19 at 17:10
2 answers
June 8th 19 at 17:12
Solution
Code web applications in Django and many other frameworks is performed only in response to a http request from the user and ends immediately after it returns the response. If the code does not return a response within a few seconds, it is forcibly terminated by the server. So even to run your code with a timer normally not work.

The easiest way to run background tasks in Django is to write your own management command and call it cron ohms. More advanced and functional way is to use some mechanism for asynchronous execution of tasks, like Celery.
June 8th 19 at 17:14
Solution
And cron poveshat not tried? He just need to run scripts on a timer.

I think you are on the side stepped up to the task. Kron to start jankowska things can or using Celery or via managers. Or even just a Python file to call, and in theit function via __main__
I.e. you can create a Python file, which prescribe the desired function (using __main__), and cron Ohm pull this file through the desired time interval?
Just where to place it? - karlee6 commented on June 8th 19 at 17:17
anywhere on the server, in the crown still need to specify the full path to the executable file - Roxanne_Ortiz commented on June 8th 19 at 17:20
, I will try, thanks for the help! - karlee6 commented on June 8th 19 at 17:23

Find more questions by tags Django