Sample Header Ad - 728x90

caffeinate can't keep display from sleeping

9 votes
2 answers
3048 views
I have a fleet of 7 macbook pro's running mac osx 10.10, 10.11, and 10.12, and 3 mac pro's running mac os 10.13 ("high sierra"). On all systems, I have set it to never sleep the system or display. Oddly, that doesn't suffice, so I also use caffeinate to prevent sleep. On the 10.13 systems, though, the display still goes to sleep, no matter what I try. This affects two things: - my opengl tests hang - "osascript -e 'tell app "System Events" to restart'" hangs Since only the display is asleep, I can still ssh in and look around. I currently run my script under caffeinate -dsiu -t 31536000, and when it hangs, evidently I've still got all the proper assertions going: $ pmset -g assertionslog 2017-11-20 19:34:27 -0800 : Showing all currently held IOKit power assertions Assertion status system-wide: BackgroundTask 0 ApplePushServiceTask 0 UserIsActive 1 PreventUserIdleDisplaySleep 1 PreventSystemSleep 1 ExternalMedia 0 PreventUserIdleSystemSleep 1 NetworkClientActive 1 and yet the display is in DevicePowerState 1: $ ioreg -n IODisplayWrangler | grep -i IOPowerManagement | | "IOPowerManagement" = {"DevicePowerState"=1,"CapabilityFlags"=0,"CurrentPowerState"=1,"MaxPowerState"=4} Executing another caffeinate -u wakes the display up and puts it into DevicePowerState 4 for 15 or so seconds, then it goes back to sleep and DevicePowerState 1, even if I give a longer timeout with -t. I've also tried repeating the -t argument after each assertion (in case the confusing manpage meant that). To rescue "osascript -e 'tell app "System Events" to restart'", I have to issue "caffeinate -u". "caffeinate -d" or "caffeinate -i" are not sufficient. See my comments at https://github.com/newmarcel/KeepingYouAwake/issues/92 for more details. I guess I should use lldb to get a backtrace from a hung opengl test, figure out what API it's hung on, and then create a minimal app that sets the appropriate power management assertion, sleeps a bit, then calls the hanging API. I'll try to do that when I get a chance. To work around it, I currently have this in a background script: while true do caffeinate -ud sleep 10 done but that's not enough; CurrentPowerState dips down to 1 frequently on all systems (though I think only the 10.13 systems actually sleep the display and hang my tests). Has anyone else run into this? Any suggestions how I can diagnose this further?
Asked by Dan Kegel (191 rep)
Nov 21, 2017, 04:31 PM
Last activity: Jun 20, 2025, 09:27 AM