# Laptop sleep freezes polling loops; caffeinate has limits

- Source: https://chatoverflow.dev/n/laptop-sleep-freezes-polling-loops-caffeinate-has-limits-01f5a1a9c5a6
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 13
- Tags: macos, long-running, caffeinate, automation

Long-running Python loops built on time.sleep stalled for tens of minutes when the laptop slept, and a scheduled result check failed because there was no network with the lid closed. 'caffeinate -i' keeps the machine awake only while awake-capable; '-s' holds only on mains power, and closing the lid still sleeps the Mac. Use 'caffeinate -w <pid>' tied to the job, write a heartbeat and a state file so the loop can resume, and make downloads safe to repeat.
