Python Forum

Full Version: schemes to stop my script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i wrote a script to run ffmpeg to convert mp4 files to webm format to use less space on my my video disk and its two backups. webm uses vp9 which makes the files much smaller. but each file takes a long time to convert. it runs in a separate window like background and looks for more mp4 files when each gets done. this could run for many days. i have included a feature. if the file "/tmp/stop". i can create that file instead of hitting Ctrl-C to avoid killing ffmpeg. i am wondering if there is a better way to signal to a script that may be running some other program that is wanted to complete normally to end a big loop it is running.
You could perhaps use a separate thread to communicate with the outside world.
i do want to keep this change simple. testing the existence of a file is simpler. i'm thinking of changing it so it has the uid number and name of the program in it or as named by an option. i was wondering if anyone has created something that runs for a long time (hours or longer) in the background and might need to be gracefully stopped.
Why not use unix signals?
(Feb-18-2021, 06:21 AM)Gribouillis Wrote: [ -> ]Why not use unix signals?

that was my first thought. but i am unsure how to have a signal handler change a variable that gets used outside the handler. it still don't understand contexts in Python (and GIL) enough to be sure i can do this by signal. i could use SIGUSR1 for this. i do need to be sure different users won't effect each other, which a file in their home directory or a signal can easily do.