Expected behavior from apps when MacOS goes to sleep

Every time macOS goes to sleep the processes get suspended which is expected. But during the sleep period, all processes keep coming back and they all get a small execution window where they make some n/w requests. Regardless of what power settings i have. It also does not matter whether my app is a daemon or not

  1. Is there any way that i can disable this so that when system is in sleep, it stays in suspended, no intermittent execution window? I have tried disabling Wake for network access setting but processes still keep getting intermittent execution window.

  2. Is there any way that i can prevent my app from coming back while in sleep. I don't want my app to get execution window, perform some executions and then get suspended not knowing when it will get execution window again?

Answered by DTS Engineer in 851907022
Every time macOS goes to sleep the processes get suspended which is expected.

Not quite. Rather, the CPU gets suspended and thus stops running any code, including app code. This is very different than, say, on iOS, where apps are typically suspended when moving to the background, regardless of whether the CPU [1] then gets suspended.

Is there any way that i can disable this so that when system is in sleep, it stays in suspended, no intermittent execution window?

No.

Is there any way that i can prevent my app from coming back while in sleep.

No.

This is simply not how macOS works. macOS can wake spontaneously under various criteria and, when it wakes, all processes will typically get execution time.

There are a bunch of subtleties here — it might only wake if it’s on power, as opposed to battery; it might wake and only given certain processes execution time; apps might go into the App Nap state and thus receive much-delayed execution time; and so on — but macOS’s sleep model is very different from iOS’s and you can’t coerce one to look like the other.

I don't want my app to get execution window … and then get suspended not knowing when it will get execution window again?

You do have various ways to control how the system gives you execution time. To point you in the right direction I need to know more about what sort of operation we’re talking about here. And specifically, why does it matter if work on that operation suspends and then resumes?

There are

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Technically this is the application processor (AP) on iOS.

Every time macOS goes to sleep the processes get suspended which is expected.

Not quite. Rather, the CPU gets suspended and thus stops running any code, including app code. This is very different than, say, on iOS, where apps are typically suspended when moving to the background, regardless of whether the CPU [1] then gets suspended.

Is there any way that i can disable this so that when system is in sleep, it stays in suspended, no intermittent execution window?

No.

Is there any way that i can prevent my app from coming back while in sleep.

No.

This is simply not how macOS works. macOS can wake spontaneously under various criteria and, when it wakes, all processes will typically get execution time.

There are a bunch of subtleties here — it might only wake if it’s on power, as opposed to battery; it might wake and only given certain processes execution time; apps might go into the App Nap state and thus receive much-delayed execution time; and so on — but macOS’s sleep model is very different from iOS’s and you can’t coerce one to look like the other.

I don't want my app to get execution window … and then get suspended not knowing when it will get execution window again?

You do have various ways to control how the system gives you execution time. To point you in the right direction I need to know more about what sort of operation we’re talking about here. And specifically, why does it matter if work on that operation suspends and then resumes?

There are

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Technically this is the application processor (AP) on iOS.

Expected behavior from apps when MacOS goes to sleep
 
 
Q