Execute specific tasks for each specific time and wait for its time (Python)
up vote
2
down vote
favorite
I would like to create a different task for every specific time and it will wait for the time and continue it day over day.
Below are my code but it only for one task.
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")
python
add a comment |
up vote
2
down vote
favorite
I would like to create a different task for every specific time and it will wait for the time and continue it day over day.
Below are my code but it only for one task.
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")
python
1
I would look into cron jobs, and use those to run your python scripts.
– Alex
Nov 12 at 7:46
1
You might consider something likecron
,launchd
or Windows Scheduler. Depending on what you have access to. Letting a single, ever running python script take care of a number of daily tasks for you is making things difficult for yourself, and probably less efficient on your CPU.. it would more sense to let these programs run your python scripts daily. unless you just want to do this for an exercise.
– Zhenhir
Nov 12 at 7:48
1
This is a dup of at least two other questions. The consensus seems to be to use theschedule
package. It's not a builtin, so you'll have to install it withpip install schedule
. See the linked threads for details on use.
– tel
Nov 12 at 7:58
Possible duplicate of How do I get a Cron like scheduler in Python?
– tel
Nov 12 at 7:59
Thanks for the feedback. How do we extract the time information inside array and assign it to Cron? As for time in "value" in my code, it will be the variable. So the actual time will wait until it match the time variable and execute the task.
– keryazmi
Nov 12 at 8:58
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I would like to create a different task for every specific time and it will wait for the time and continue it day over day.
Below are my code but it only for one task.
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")
python
I would like to create a different task for every specific time and it will wait for the time and continue it day over day.
Below are my code but it only for one task.
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")
python
python
asked Nov 12 at 7:43
keryazmi
111
111
1
I would look into cron jobs, and use those to run your python scripts.
– Alex
Nov 12 at 7:46
1
You might consider something likecron
,launchd
or Windows Scheduler. Depending on what you have access to. Letting a single, ever running python script take care of a number of daily tasks for you is making things difficult for yourself, and probably less efficient on your CPU.. it would more sense to let these programs run your python scripts daily. unless you just want to do this for an exercise.
– Zhenhir
Nov 12 at 7:48
1
This is a dup of at least two other questions. The consensus seems to be to use theschedule
package. It's not a builtin, so you'll have to install it withpip install schedule
. See the linked threads for details on use.
– tel
Nov 12 at 7:58
Possible duplicate of How do I get a Cron like scheduler in Python?
– tel
Nov 12 at 7:59
Thanks for the feedback. How do we extract the time information inside array and assign it to Cron? As for time in "value" in my code, it will be the variable. So the actual time will wait until it match the time variable and execute the task.
– keryazmi
Nov 12 at 8:58
add a comment |
1
I would look into cron jobs, and use those to run your python scripts.
– Alex
Nov 12 at 7:46
1
You might consider something likecron
,launchd
or Windows Scheduler. Depending on what you have access to. Letting a single, ever running python script take care of a number of daily tasks for you is making things difficult for yourself, and probably less efficient on your CPU.. it would more sense to let these programs run your python scripts daily. unless you just want to do this for an exercise.
– Zhenhir
Nov 12 at 7:48
1
This is a dup of at least two other questions. The consensus seems to be to use theschedule
package. It's not a builtin, so you'll have to install it withpip install schedule
. See the linked threads for details on use.
– tel
Nov 12 at 7:58
Possible duplicate of How do I get a Cron like scheduler in Python?
– tel
Nov 12 at 7:59
Thanks for the feedback. How do we extract the time information inside array and assign it to Cron? As for time in "value" in my code, it will be the variable. So the actual time will wait until it match the time variable and execute the task.
– keryazmi
Nov 12 at 8:58
1
1
I would look into cron jobs, and use those to run your python scripts.
– Alex
Nov 12 at 7:46
I would look into cron jobs, and use those to run your python scripts.
– Alex
Nov 12 at 7:46
1
1
You might consider something like
cron
,launchd
or Windows Scheduler. Depending on what you have access to. Letting a single, ever running python script take care of a number of daily tasks for you is making things difficult for yourself, and probably less efficient on your CPU.. it would more sense to let these programs run your python scripts daily. unless you just want to do this for an exercise.– Zhenhir
Nov 12 at 7:48
You might consider something like
cron
,launchd
or Windows Scheduler. Depending on what you have access to. Letting a single, ever running python script take care of a number of daily tasks for you is making things difficult for yourself, and probably less efficient on your CPU.. it would more sense to let these programs run your python scripts daily. unless you just want to do this for an exercise.– Zhenhir
Nov 12 at 7:48
1
1
This is a dup of at least two other questions. The consensus seems to be to use the
schedule
package. It's not a builtin, so you'll have to install it with pip install schedule
. See the linked threads for details on use.– tel
Nov 12 at 7:58
This is a dup of at least two other questions. The consensus seems to be to use the
schedule
package. It's not a builtin, so you'll have to install it with pip install schedule
. See the linked threads for details on use.– tel
Nov 12 at 7:58
Possible duplicate of How do I get a Cron like scheduler in Python?
– tel
Nov 12 at 7:59
Possible duplicate of How do I get a Cron like scheduler in Python?
– tel
Nov 12 at 7:59
Thanks for the feedback. How do we extract the time information inside array and assign it to Cron? As for time in "value" in my code, it will be the variable. So the actual time will wait until it match the time variable and execute the task.
– keryazmi
Nov 12 at 8:58
Thanks for the feedback. How do we extract the time information inside array and assign it to Cron? As for time in "value" in my code, it will be the variable. So the actual time will wait until it match the time variable and execute the task.
– keryazmi
Nov 12 at 8:58
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
I have implemented in my project and it's working properly. Please have a look on below code.
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
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257740%2fexecute-specific-tasks-for-each-specific-time-and-wait-for-its-time-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I have implemented in my project and it's working properly. Please have a look on below code.
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
add a comment |
up vote
0
down vote
I have implemented in my project and it's working properly. Please have a look on below code.
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
add a comment |
up vote
0
down vote
up vote
0
down vote
I have implemented in my project and it's working properly. Please have a look on below code.
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
I have implemented in my project and it's working properly. Please have a look on below code.
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
answered Nov 12 at 7:51
Anoop Kumar
19013
19013
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257740%2fexecute-specific-tasks-for-each-specific-time-and-wait-for-its-time-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I would look into cron jobs, and use those to run your python scripts.
– Alex
Nov 12 at 7:46
1
You might consider something like
cron
,launchd
or Windows Scheduler. Depending on what you have access to. Letting a single, ever running python script take care of a number of daily tasks for you is making things difficult for yourself, and probably less efficient on your CPU.. it would more sense to let these programs run your python scripts daily. unless you just want to do this for an exercise.– Zhenhir
Nov 12 at 7:48
1
This is a dup of at least two other questions. The consensus seems to be to use the
schedule
package. It's not a builtin, so you'll have to install it withpip install schedule
. See the linked threads for details on use.– tel
Nov 12 at 7:58
Possible duplicate of How do I get a Cron like scheduler in Python?
– tel
Nov 12 at 7:59
Thanks for the feedback. How do we extract the time information inside array and assign it to Cron? As for time in "value" in my code, it will be the variable. So the actual time will wait until it match the time variable and execute the task.
– keryazmi
Nov 12 at 8:58