Start a Function at Given Time

Reading the docs from http://docs.python.org/py3k/library/sched.html: Going from that we need to work out a delay (in seconds)… from datetime import datetime now = datetime.now() Then use datetime.strptime to parse ‘2012-07-17 15:50:00’ (I’ll leave the format string to you) # I’m just creating a datetime in 3 hours… (you’d use output from above) from datetime import … Read more

Python script to do something at the same time every day [duplicate]

I spent quite a bit of time also looking to launch a simple Python program at 01:00. For some reason, I couldn’t get cron to launch it and APScheduler seemed rather complex for something that should be simple. Schedule (https://pypi.python.org/pypi/schedule) seemed about right. You will have to install their Python library: pip install schedule This … Read more

How can I run an external command asynchronously from Python?

subprocess.Popen does exactly what you want. from subprocess import Popen p = Popen([‘watch’, ‘ls’]) # something long running # … do other stuff while subprocess is running p.terminate() (Edit to complete the answer from comments) The Popen instance can do various other things like you can poll() it to see if it is still running, … Read more