Skip to content

hetalang/NoSleep.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NoSleep.jl

Autotest version GitHub issues GitHub license Julia package downloads

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
  • Simple API: block-style or manual on/off.
  • Safe by design: resets on exit; optional timeout.

Installation

] add NoSleep

using NoSleep

Usage

Macros style:

@nosleep begin
    # long-running code here
end

Block style:

with_nosleep() do
    # long-running code here
end

Manual style:

nosleep_on()
# long-running code here
nosleep_off()

Extra options

keep_display

The keep_display option prevents the screen from going to sleep (default is false).

@nosleep keep_display=true begin
    # long-running code here
end
with_nosleep(keep_display=true) do
    # long-running code here
end

timeout_seconds (experimental)

The 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
end

Known limitations and recommendations

Some sleep behaviors are enforced by the operating system and cannot be overridden by NoSleep.jl or any similar tools.

  1. Closing the laptop lid or pressing the power button will force the system into sleep regardless of active sleep-prevent requests of NoSleep.jl.

  2. 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=true to keep the screen awake.

Authors

License

MIT (see LICENSE).

About

Tiny package to prevent sleep mode

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages