I have a Python script that I want to run after Kodi loads and to keep running indefinitely. (The script launches a slideshow under control of an external gesture sensor wired to the Pi.)
I created an autoexec.py script and saved it in /home/osmc/.kodi/userdata
The script runs nicely after reboot and Kodi loads, but then terminates.
Here’s the Python code:
#!/usr/bin/python3.4
import os, sys, subprocess
fpid= os.fork()
if fpid!=0:
#Running as daemon now with PID fpid; exit the parent
sys.exit(0)
subprocess.call("sudo /home/osmc/scripts/GestureCommands.sh", shell=True)
(The shell script GestureCommands.sh contains a while loop that keeps it running and checking for sensor input.)
Examining ~/.kodi/temp/kodi.log, I see the problem:
00:22:15 T:1780458528 NOTICE: -->Python Interpreter Initialized<--
00:22:15 T:1780458528 WARNING: CPythonInvoker(3): Script invoked without an addon. Adding all addon modules installed to python path as fallback. This behaviour will be removed in future version.
00:22:16 T:1676669984 NOTICE: Thread BgPicLoader start, auto delete: false
00:22:21 T:1780458528 ERROR: CPythonInvoker(0, /usr/share/kodi/addons/script.module.osmcsetting.updates/service.py): script didn't stop in 5 seconds - let's kill it
CPythonInvoker is apparently playing nanny and killing my script.
How do I prevent this?
I should mention that I previously tried running GestureCommands.sh from /etc/rc.local and also tried adding it to systemd, and I couldn’t get either of those approaches to work either. I’m just looking for the simplest way to daemonize a bash script. Anyone have any suggestions?