def message_received(connect_object, message_node):
// if x event happens:
exit()
jid = xmpp.JID(user)
connection = xmpp.Client(jid.getDomain(), debug=[])
connection.connect(server)
result = connection.auth(jid.getNode(), password, "qwerty")
connection.RegisterHandler('message', message_received)
connection.sendInitPresence()
while connection.Process(1):
pass
Irrespective of what the above code does, I want to keep sending a message to a recipient once every hour as a reminder for something. Even if a message is received and the control goes to the message_received function, the message to be sent every hour should continue unless exit() was encountered.
Where do I insert the message? I want to use time.sleep() but any other solution is also acceptable.
If you're okay with using another utility to do this, I would prefer to use another tool (e.g., cron/anacron for *nixes) to run a short script that exits quickly and sends the message.
This method has some benefits:
Edit: I missed the need to halt on 'exit' command. If you use crontab, you can use python-crontab to automatically insert/remove the crontab entry for this job.