octoprint_ffmpeg_script/stream_stop.py
2021-02-13 22:35:28 +01:00

30 lines
620 B
Python
Executable File

#!/usr/bin/env python3
import subprocess, os, signal, sys, time
from constants import *
if len(sys.argv) > 1:
wait_delay = float(sys.argv[1])
else:
wait_delay = 0
pid_path = os.path.join("/tmp", PIDFILE)
if os.path.exists(pid_path):
with open(pid_path, "r") as pid_file:
kill_pid = pid_file.read().strip()
# wait the specified number of seconds
time.sleep(wait_delay)
try:
os.kill(int(kill_pid), signal.SIGINT)
os.unlink(pid_path)
print("Stopped stream")
except Exception as err:
print("Error occured while killing process:", repr(err))
else:
print("No pidfile found")
# else do nothing I guess