Macbook falling asleep when locking the screen even when plugged in

When plugged in, I want my macbook to stay awake unless I explicitly put it to sleep. But no matter how I change the settings, it still falls asleep when I lock the screen, even if it is plugged in.


I did the following:

  • System Settings > Battery > Power Adapter
  • Turn display off after = Never
  • All other checkboxes unchecked, except for 'Wake for network access'


Am I missing something here?


Thx.

MacBook Pro 13″, macOS 10.14

Posted on Jan 10, 2023 5:33 AM

Reply

Similar questions

12 replies

Jan 13, 2023 5:02 AM in response to alain_desilets

Ok, I took a break and let my mac sleep for around ten minutes. This time there was a ten-minute gap, as expected.


I am on Ventura, and the organization of preferences (now called "settings") is different.

I no longer have a Monterey running mac to compare, but there were different settings - including "prevent mac from sleeping when the display is off" (or similar wording). Do you have that one checked? You probably do, but it is worth confirming.


Also: a test similar to mine may help confirm that your mac is indeed going to sleep (when you expected it NOT to): if you have Music playing something, Sleep should pause it, whereas just locking the screen should not.


Jan 13, 2023 9:27 AM in response to Luis Sequeira1

Luis Sequeira1 wrote:

Ok, I took a break and let my mac sleep for around ten minutes. This time there was a ten-minute gap, as expected.

So, same as me.

I am on Ventura, and the organization of preferences (now called "settings") is different.
I no longer have a Monterey running mac to compare, but there were different settings - including "prevent mac from sleeping when the display is off" (or similar wording). Do you have that one checked? You probably do, but it is worth confirming.

Attached is a screenshot of my Power Adaptor settings

Also: a test similar to mine may help confirm that your mac is indeed going to sleep (when you expected it NOT to): if you have Music playing something, Sleep should pause it, whereas just locking the screen should not.


OK, so I ran the python script for 5 mins while Apple Music was playing some local MP3s (so no network access) and the screen was locked. The music did not stop playing and after 5 mins I unlocked the screen and I didn't see any gaps in the times output by the Python script.


Then I ran the script just by itself (no Apple Music playing) for 5 mins with screen lock and this time there was a 4mins gap as before.


So, it seems Apple Music prevents the machine from going to sleep but not my python script.


Note that I also tried with Apple Music playing and setting "Wake for network access" unchecked and the result was the same. The music kept playing and there was no gap in the timestamps produced by the python script.


I am completely baffled.


Alain


Alain

Jan 14, 2023 9:04 AM in response to Luis Sequeira1

Luis Sequeira1 wrote:

Read this line carefully:


https://discussions.apple.com/content/attachment/c6cf4c44-de96-41c9-b80f-8c9d31ff36d4

Now tell me: do you want to check this box or not?

Of course you do!

Oops. Actually, one of the first thing I did when I started investigating this strange behavior was to check that box. Since then, I must have unchecked it by accident.


I just re-checked it and ran the Python script (without music playing) and I still see gaps. So checking that box does not solve the problem for me.


Still baffled ;-).


Alain

Jan 12, 2023 4:42 PM in response to Shannon_DN

Since this is a program not developed by Apple, we cannot use it as an indicator on if the computer is going to sleep or not. 


Of course I can. Here is the program (it's a small Python script):


import time

from datetime import datetime


if __name__ == "__main__":

print("Starting")

counter = 0

while(True):

counter += 1

currentDateAndTime = datetime.now()

print("counter=%s; now=%s" % (counter, currentDateAndTime))

time.sleep(10.0)


I start this program, then lock the screen by pressing Ctrl+Shift+Power. The screen goes dark for a second and then I see the login screen.


After 5 minutes, I enter my password and this is what I see as the output of the Python script:


Starting

counter=1; now=2023-01-12 19:22:30.455574

counter=2; now=2023-01-12 19:22:40.456265

counter=3; now=2023-01-12 19:22:50.457830

counter=4; now=2023-01-12 19:23:00.461610

counter=5; now=2023-01-12 19:23:10.461646

counter=6; now=2023-01-12 19:23:20.465708

counter=7; now=2023-01-12 19:23:30.468552

counter=8; now=2023-01-12 19:23:40.469337

counter=9; now=2023-01-12 19:23:50.470197

counter=10; now=2023-01-12 19:24:00.475407

counter=11; now=2023-01-12 19:24:10.476329

counter=12; now=2023-01-12 19:24:20.483302

counter=13; now=2023-01-12 19:28:30.002651

counter=14; now=2023-01-12 19:28:40.770993


Everything looks normal between counter=1 and counter=12, i.e. the time printed at each iteration is 10 secs later than the time printed at the previous iteration.


But notice the 4m10s mins gap between counter=12 and counter=13. This means the program was not running for the 4m10s between 19:24:20 and 19:28:30.


The only possible explanation is that the computer went to sleep and was not running the program during that time.



Jan 12, 2023 3:46 PM in response to Dustin_R_308

When you go to a Lock Screen on your Mac, what is indicating to you that the machine is asleep? You can learn more about Lock Screen settings here:

Dustin_R_308 wrote:

Greetings alain_desilets,

When you go to a Lock Screen on your Mac, what is indicating to you that the machine is asleep? You can learn more about Lock Screen settings here:

Change Lock Screen settings on Mac - Apple Support

Take care.


I wrote a program that increments and prints a counter every 10 seconds.


I start the program then lock my screen and unlock it after 5 minutes. At this point I would expect the counter to be at 30 (5 * 6), but it's around 120 (which means it fell asleep after about 2 mins).

Jan 13, 2023 3:04 AM in response to alain_desilets

alain_desilets wrote:

But notice the 4m10s mins gap between counter=12 and counter=13. This means the program was not running for the 4m10s between 19:24:20 and 19:28:30.

The only possible explanation is that the computer went to sleep and was not running the program during that time.


I should also point out that if I run the program for 5 minutes without locking the screen, no such gap occurs. The time displayed at every single iteration is 10 secs later than the previous one.


So clearly, the problem is not with my program. It's an issue of the mac falling asleep after about 2 mins when the screen is locked.

Jan 13, 2023 4:10 AM in response to alain_desilets

I tried your code on my mac (intel MBP, Ventura 13.1 and Python 3.9.15).


When I locked the screen, there were no gaps at all. It continued to count each 10 seconds.


But then it became weirder... I set the mac to sleep for about a minute, woke it up and... there were still no gaps ?!!! It still showed all the times and dates, 10 seconds apart, even in the period where the mac was supposedly asleep.


And if you are thinking: "he must not have put his mac to sleep"... I can understand why.

But not just I selected sleep from the Apple menu, I had music playing in a Safari page. The music plays on when the screen is locked, but it stops when the mac is put to sleep (as it should).


Incidentally, which version of Python are you using?

Jan 13, 2023 4:34 AM in response to Luis Sequeira1

Luis Sequeira1 wrote:

But then it became weirder... I set the mac to sleep for about a minute, woke it up and... there were still no gaps ?!!! It still showed all the times and dates, 10 seconds apart, even in the period where the mac was supposedly asleep.

This is so weird! Did you let the mac sleep for at least a minute? If you put it to sleep and woke it up right after, there might not be gaps.


Incidentally, which version of Python are you using?


Python 2.7.13


Alain

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Macbook falling asleep when locking the screen even when plugged in

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.