Skip to content

hetalang/NoSleepMatlab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NoSleepMatlab

Continuous Integration GitHub issues License: MIT CodeQL Release View NoSleep on File Exchange

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
  • 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.

Installation from MATLAB File Exchange

  1. Go to https://www.mathworks.com/matlabcentral/fileexchange/183008-nosleepmatlab
  2. Click Download and save the .mltbx file.
  3. Install by double-clicking the .mltbx file

Installation from GitHub

  1. Download the latest release file NoSleep.mltbx from
    https://github.com/hetalang/NoSleepMatlab/releases

  2. Install by double-clicking the .mltbx file
    or run:

matlab.addons.install('NoSleep.mltbx');

Basic usage

import NoSleep.*

nosleep_on();
% long-running MATLAB code here
nosleep_off();

Block-style usage

with_nosleep runs a function while sleep-prevention is active and restores normal behavior afterwards:

with_nosleep(@() myLongComputation());

Options

keep_display

Prevents the display from turning off (default: false):

nosleep_on(true);

Block-style:

with_nosleep(@() myLongComputation(), true);

Known limitations and recommendations

Some sleep behaviors are enforced by the operating system and cannot be overridden by MATLAB or this toolbox.

  1. Closing the laptop lid or pressing the power button forces sleep regardless of active PowerRequest or other inhibit mechanisms.

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

Related packages

For developers

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.table

Author

License

MIT (see LICENSE.md).

About

Matlab tool to prevent sleep mode

Resources

License

Stars

Watchers

Forks

Packages

No packages published