3

I'd like to keep my Python script running, even when my computer is sleeping.

I am using a Mac.

My file is only on my computer, not online.

I know of UptimeRobot, but I don't know how to configure that to my local file.

I would prefer to keep my file local, because it makes a lot of things easier for my project.

Is there anything that can help me achieve this? (not hardware, thanks.)

If you need more information, please leave a comment!

  • 1
    If on Win, wrap it in a `cmd` (batch) script and set it up as a service. If on Linux, add it to `systemd.` Here is a nice and simple `systemd` [tutorial](https://www.raspberrypi.org/documentation/linux/usage/systemd.md). – S3DEV Apr 17 '20 at 12:19
  • You can use [Py2Exe](https://www.py2exe.org/) to turn the script into an executable. – TheLazyScripter Apr 17 '20 at 12:20
  • 1
    @S3DEV Hmm, a batch script makes so much more sense. – TheLazyScripter Apr 17 '20 at 12:21
  • What do you mean "even when my computer is sleeping"? Like when computer is in Sleep Mode? – Thaer A Apr 17 '20 at 12:23
  • Is it a windows or a Mac/Linux machine? – kpython Apr 17 '20 at 12:25
  • Take a look at this https://stackoverflow.com/a/59125542/5260872 – Nishan Apr 17 '20 at 12:31
  • Thanks guys. I'm on a mac if that helps. – Liam Williamson Apr 17 '20 at 12:45
  • Since you're on a mac, there is some good info here - [Running Python in background on OS X](https://stackoverflow.com/questions/9522324/running-python-in-background-on-os-x). I run things on a "sleepy" computer, but I use `pmset sleep 0` to prevent the computer from sleeping. Do a `man pmset` and run the `pmset -g` command to see what your current settings are. – Rusty Widebottom Apr 17 '20 at 16:07

1 Answers1

12

It's very simple.

  1. open a terminal

  2. type caffeinate

  3. press Enter

Once you have done this, your Mac will stay awake for as long as you leave the Terminal running.

You can minimize or hide it, and your Mac will not go to sleep until you use the keyboard shortcut Ctrl+C to interrupt the command.

source

JacoSolari
  • 1,226
  • 14
  • 28
  • 2
    This is the only time that apple has had a one line answer to one of my questions regarding the terminal – amstrudy Oct 06 '22 at 21:53