I’d like to control a bash program from within Python. I’d like to run an external command every x seconds for y seconds, and then kill it after y seconds. I’m having a bit of trouble with threads and sleep and wait and etc. and am wondering if someone can post a simple example.
For example, from the CLI the usage might be
./foo.py --runfor=10 --runevery=60
meaning foo.py would run something for 10 seconds every 60 seconds (not 60 seconds between). If it is off by a second or fractions of a second that is OK. I can do this by spawning a process that is blocking, and then doing some math to set the timer, but I think there might be a more elegant way with threads.
does this help?