Prevent your machine from going to sleep while long-running Julia jobs are executing — and automatically restore normal behavior when they finish or fail.
- Cross-platform backend
- Windows:
SetThreadExecutionState - macOS:
caffeinate - Linux:
systemd-inhibit
- Windows:
- Simple API: block-style or manual on/off.
- Safe by design: resets on exit; optional timeout.
] add NoSleep
using NoSleepMacros style:
@nosleep begin
# long-running code here
endBlock style:
with_nosleep() do
# long-running code here
endManual style:
nosleep_on()
# long-running code here
nosleep_off()The keep_display option prevents the screen from going to sleep (default is false).
@nosleep keep_display=true begin
# long-running code here
endwith_nosleep(keep_display=true) do
# long-running code here
endThe timeout_seconds option sets a timeout in seconds after which the nosleep mode is automatically disabled (default is Inf, meaning no timeout).
with_nosleep(; keep_display=true, timeout_seconds=600) do
# long-running code here
endSome sleep behaviors are enforced by the operating system and cannot be overridden by NoSleep.jl or any similar tools.
-
Closing the laptop lid or pressing the power button will force the system into sleep regardless of active sleep-prevent requests of
NoSleep.jl. -
On Windows devices with Modern Standby (S0ix) running on battery power (DC mode) the OS may ignore sleep prevention signals after a 5 minutes of inactivity if the screen is turned off.
- Connect charger (AC mode) to avoid this.
- OR use
keep_display=trueto keep the screen awake.
MIT (see LICENSE).