Running simple script in background
-
I'm trying to execute a simple script in Python via my iPhone in order to keep alive a Buffalo NAS drive by sending a magic packet every 3 minutes. The script works well as long as I have the Python app open in the foreground but as soon as it moves to the background it looks like it stops executing and the NAS turns off.
Is this a limitation of iOS rather than the python app(s) I'm using? Running on android via QPython in the background seems to work well
-
This is a limitation/feature of iOS. Apps can only run in the background for a couple of minutes before they're suspended by the system, in order to conserve system resources (and improve battery life).
-
It would be a nice use case for a Raspberry Pi Zero W ;-)
-
@omz many thanks for the confirmation, i can now stop wasting time trying to figure a workaround on ios and use Android.
-
@ccc I'm presuming you mean in such a way as using something like VNC on the iPhone to connect to the Pi and trigger the python script on the Pi which is connected to the home network?
-
Either that or maybe even more simply on the Pi just run a script of the form:
import time while True: # This minimum viable script runs 24 * 7 * 365 send_magic_bytes() time.sleep(3 * minutes)
-
I use crontab on Zero W to run a periodical Python script, in my case storing temperature data from several sensors to the cloud.
My Zero W does not have a screen or a keyboard, but development experience was nice anyway with a Pythonista action that uses ssh to dump the script to Pi W and run it.