Code I have
def callback(message):
if not message:
Mailer().send_feed_error_report('Empty Message')
if "message_type" not in message:
Mailer().send_feed_error_report('"message_type" not in message')
class Mailer():
def send_feed_error_report(self, error_info):
send_mail(error_info)
callback(message)
send_mail will only send a mail. It is a simple function for sending mail.
I want to
- send mail only after 1 hour
- other functions/code has to run in parallel, so I'd like to avoid using
time.sleep()
Scheduling in Python
You can use
threading.Timerto schedule a function to run after a specified time (delay).See Python's Event scheduler module
sched.How it works
Passing the delay in seconds will start the thread after the given delay and execute it independent of the main thread. Hence does not block your main thread.
You can pass parameters to your function like a regular thread using
argsas third argument.Source: Start a Function at Given Time