added stream stop delay

This commit is contained in:
Jan Scheiper 2021-02-13 22:35:28 +01:00
parent 9c2a3dc490
commit 6f47cd63f4
2 changed files with 11 additions and 3 deletions

View File

@ -1,4 +1,4 @@
# Octoprint ffmpeg # Octoprint ffmpeg stream script
To get started copy `constants.example.py` to `constants.py`: To get started copy `constants.example.py` to `constants.py`:
@ -22,5 +22,5 @@ You can now start the stream by simply running
and stop the stream with and stop the stream with
``` ```
./stream_stop.py ./stream_stop.py [wait_seconds]
``` ```

View File

@ -1,14 +1,22 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import subprocess, os, signal import subprocess, os, signal, sys, time
from constants import * 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) pid_path = os.path.join("/tmp", PIDFILE)
if os.path.exists(pid_path): if os.path.exists(pid_path):
with open(pid_path, "r") as pid_file: with open(pid_path, "r") as pid_file:
kill_pid = pid_file.read().strip() kill_pid = pid_file.read().strip()
# wait the specified number of seconds
time.sleep(wait_delay)
try: try:
os.kill(int(kill_pid), signal.SIGINT) os.kill(int(kill_pid), signal.SIGINT)