Python Forum
schemes to stop my script - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: schemes to stop my script (/thread-32541.html)



schemes to stop my script - Skaperen - Feb-17-2021

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.


RE: schemes to stop my script - Gribouillis - Feb-17-2021

You could perhaps use a separate thread to communicate with the outside world.


RE: schemes to stop my script - Skaperen - Feb-18-2021

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.


RE: schemes to stop my script - Gribouillis - Feb-18-2021

Why not use unix signals?


RE: schemes to stop my script - Skaperen - Feb-21-2021

(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.