How to have Python script run continuously..

Discussion in 'Mac Programming' started by crashwins, Sep 14, 2016.

  1. crashwins macrumors member

    Joined:
    Sep 11, 2009
    #1
    Not sure how to keep this script running given my computer times out, goes to sleep, shuts down hard drives, etc, when I'm not sitting there. I guess there's LittleSnitch, but how should I keep this script running on my iMac (short of buying a RaspberryPi and using that as a little server, which would be a PITA)? Anyone advice would be most welcome -- thank you!
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    1. If you want your computer to act as a server, you need to disable sleep completely.

    You can keep "Spin down disk" enabled, as it will automatically spin up again when needed. The main effect of disk spindown is that the first client request after spindown that needs the disk will take several seconds. Subsequent client requests within the spindown window will be fast. This only applies to a spinning disk, not an SSD.

    I run a Mac mini as a server like this: sleep disabled, spindown at 10 mins.


    2. If you only run your Python script sometimes, and don't want to disable sleep completely, then use the 'caffeinate' cmd when you run your script.
    https://developer.apple.com/legacy/...win/Reference/ManPages/man8/caffeinate.8.html

    If you then terminate your script, the sleep-disabling assertion will disappear, and the machine will sleep again using whatever timeouts are in force.


    3. Personally, I might not rule out a Pi. Pi Zero, $5:
    https://www.adafruit.com/product/2885

    It depends on a number of factors, mostly involving power supply, connectors, and what I wanted the server to do overall, but $5 is pretty cost-effective.
     
  3. Osty macrumors 6502a

    Joined:
    Jul 15, 2008
    Location:
    Melbourne, AU
    #3
    I use a Raspberry Pi 2 as my always on server. Can't fault it to be honest.
     

Share This Page