Attention: After testing this approach for a while I found out it didn't fix the problem in general
NOT WORKING:
Although I didn't test running my program for several hours, this seems to do the trick.
from threading import Thread
from time import sleep
import subprocess
def bluetooth_stay_awake():
"""Ping the bluetooth compontent to keep all connections up"""
thread= Thread(target=(lambda:subprocess.run(["watch", "bluetoothctl"])))
thread.start()
Using the shell command watch bluetoothctl
is important here, otherwise the bluetoothctl
process would block you python script.
Shell Commands & Threading in Python