Question

I have noticed that sometimes when I open my laptop the battery had dropped to 99% or even 97% after a day or so.

I have it set up to sleep after being closed for 5 seconds, and I've verified that by seeing that if it is closed for longer than five seconds I need to use touch-ID or a password to start using it.

There's probably a smarter way to find out or look up if/when it last entered sleep mode, but I don't know of it.

But sometimes while working I suddenly need to stop for hours or longer, and in some cases I am running Python from iTerm2 and have a matplotlib plot open that I don't want to close (I use widgets and it has a control panel and settings I want to continue to use later).

And sometimes I notice that when I open my MacBook Air again the battery is down.

Testing, I see that I still need to use touch ID after 5 seconds when in this state.

Questions:

  1. Could running Python and Matplotlib be keeping my computer from sleeping?
  2. Is there some way I can find out or look up if/when it last entered sleep mode? This will be helpful in debugging of this problem.

power settings power settings

click for full size

Was it helpful?

Solution

I have noticed that sometimes when I open my laptop the battery had dropped to 99% or even 97% after a day or so.

A 1 to 3% drop in battery over a 24 to 48 hour period is very normal and expected. When you put your Mac to sleep, any processes will be suspended (provided you don't close the iTerm windows).

The small drop in battery is likely due to PowerNap (MacBook Air support since 2010) which will periodically wake the computer to check for email, updates, sync iCloud documents, messages, notes etc.

Could running Python and Matplotlib be keeping my computer from sleeping?

Could it? Yes. But based on the symptoms you presented, no it's not. Your Mac wouldn't go for "a day or two" and only lose 1-3% charge if there was an active process preventing it from sleeping. A super easy way to confirm this is to check the process of the script (you never mentioned what it does so my answer is generic here), if the script has finished or made progress during that time then it was obviously running. If it's right where you left it, then your Mac was asleep.

Is there some way I can find out or look up if/when it last entered sleep mode? This will be helpful in debugging of this problem.

There's no problem to debug.

What you're seeing is completely normal. A 1-3% (average 2%) battery charge drop over "a day or so" is well within the norm even with PowerNap disabled. If your Mac wasn't sleeping, your complaint would be vastly different - it would be that the battery drained completely and crashed your app/process. To diagnose that issue, you'd issue the command

% pmset -g assertions

That will tell you what's preventing your Mac from sleeping. It should return zeros.

The other reason why "a problem" shouldn't be assumed is that there's a very important distinction between sleep and hibernation. When your Mac sleeps, the CPU goes into a lower power mode (not off) and the current state is held in memory (there's a lot more, but let's limit it to these major functions). This means there is a power draw. If you want to stop the power draw (technically you can't completely stop a battery from discharging due to physics and chemistry governing the battery), you have to hibernate your computer. This is where the state will be written to disk and the power turned off.

Now, to see when your Mac went to sleep, you can obtain the log from pmset as well:

% pmset -g log | grep -i "sleep\|wake" 

The problem with this is that with the newer versions of macOS, the computer will still wake for arbitrary reasons even with PowerNap disabled. I know this because I can hear a bar code scanner "reset" (it makes a tone when connected to USB) periodically even though I have the Mac sleeping with PowerNap disabled. For some reason, it resets the USB bus. I haven't investigated this more because a) it happens on every Mac I've used and b) the Mac has never had any ill effects when woken. All processes were suspended as they were supposed to.

By limiting the scope of symptoms to the drop in battery charge over a period of days, you'll end up looking for solution to a non-problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with apple.stackexchange
scroll top