我想为每个特定时间创建一个不同的任务,它将等待该时间并日复一日地继续执行。
下面是我的代码,但仅用于一项任务。
import time, datetime
time_now = time.localtime(time.time())
now = []
now = time.strftime("%H:%M:%S", time_now)
value = []
value = time.strftime("15:00:00")
print(now)
print(value)
while value == now:
time.sleep(1)
print("\nSuccess")
答案 0 :(得分:0)
我已经在我的项目中实施了项目,并且工作正常。请看下面的代码。
from django.http import HttpResponse, StreamingHttpResponse
from django.views.decorators.http import condition
import time
@condition(etag_func=None)
def stream(request):
resp = StreamingHttpResponse(stream_response_generator(request))
return resp
def stream_response_generator(request):
start = time.time()
end = start + 60
while start < end:
#Here you can add your method
print ("This is test") # will print after 60 secound after frist executing of time
time.sleep(2) # sleep time added