Matlab tool to prevent sleep mode
Prevent your computer from going to sleep while MATLAB is running long tasks — and automatically restore normal system behavior when the task finishes or fails.
- Cross-platform backend
- Windows:
PowerRequest - macOS:
caffeinate - Linux:
systemd-inhibit
- Windows:
- Simple API: block-style or manual on/off.
- Safe by design: the sleep-inhibit request is always released on exit or error.
- Optional keep_display mode to prevent the screen from turning off.
- Go to https://www.mathworks.com/matlabcentral/fileexchange/183008-nosleepmatlab
- Click Download and save the
.mltbxfile. - Install by double-clicking the
.mltbxfile
-
Download the latest release file
NoSleep.mltbxfrom
https://github.com/hetalang/NoSleepMatlab/releases -
Install by double-clicking the
.mltbxfile
or run:
matlab.addons.install('NoSleep.mltbx');import NoSleep.*
nosleep_on();
% long-running MATLAB code here
nosleep_off();with_nosleep runs a function while sleep-prevention is active and restores normal behavior afterwards:
with_nosleep(@() myLongComputation());Prevents the display from turning off (default: false):
nosleep_on(true);Block-style:
with_nosleep(@() myLongComputation(), true);Some sleep behaviors are enforced by the operating system and cannot be overridden by MATLAB or this toolbox.
-
Closing the laptop lid or pressing the power button forces sleep regardless of active PowerRequest or other inhibit mechanisms.
-
On Windows devices with Modern Standby (S0ix) on battery power, the OS may ignore sleep-prevention signals after ~5 minutes of inactivity when the display is off.
- Plugging into AC power avoids this behavior.
- Alternatively, use keep_display
trueto keep the screen awake.
-
NoSleepR — https://github.com/hetalang/NoSleepR
R implementation using system-level sleep-inhibit APIs. -
NoSleep.jl — https://github.com/hetalang/NoSleep.jl
Julia implementation with the same backend logic (Windows/macOS/Linux).
Toolbox rebuild:
mex -output +NoSleep/private/nosleep_win csrc/nosleep_win.c
matlab.addons.toolbox.packageToolbox('NoSleep.prj','dist/NoSleep.mltbx')Run tests:
results = runtests("tests")
results.tableMIT (see LICENSE.md).