Scilab Home page | Wiki | Bug tracker | Forge | Mailing list archives | ATOMS | File exchange
Please login or create an account
Change language to: Français - Português - 日本語 - Русский
Scilab Help >> Time and Date > sleep


suspend all code executions (console, scripts, callbacks,..)


sleep(seconds, "s")


duration of the sleep, in milliseconds (decimal number)
duration of the sleep, in seconds (decimal number)


sleep stops Scilab processing any instruction for a specified number of milliseconds or seconds:

input and output in console are suspended.
The CTRL-C interruption is caught but performed only at the end of the sleep.
Scripts and functions:
When sleep(..) is called inside a script or a function, Scilab waits for the given duration before processing the next instruction. CTRL-C in the console is caught but performed only at the end of the sleep.
.. are actions triggered by interactions with menus and with uicontrol interactive graphical components. During the sleep(..), these interactions are caught, and related instructions are buffered. Buffered actions are all performed after sleep()'s end.
Graphics interactions:
sleep(..) does not prevent interacting with graphics, providing that the interaction mode has been turned on before entering the sleep. Then, moving curves, editing graphics labels, etc is still possible during Scilab's sleep. The wake-up does not reset these actions.

Time resolution:
  • Windows systems: 0.5 ms
  • Linux systems: 1 µs
Time resolution is not.. time accuracy: The actual suspension time may be longer than the specified one, due to other processes run in the system, or due to the time spent to process the call.


// Simple examples
tic; sleep(4350); toc
tic; sleep(4.35, "s"); toc

// Testing the sleep's accuracy:
results = [];
disp("Please wait... sleep()s and wake-up are performed...")
for i = -1:4
    dt = 10^i;        // specified duration [ms]
    dta = toc()*1000; // actual duration [ms]
    results = [results ; dt dta ];

// Test of the CTRL-C interruption:
disp("Press CTRL + C keys now: the 15 s sleep is going on")

// Test of interactions with menus:
// [If you are a MacOS user, select the menu "Edit=> Clear figure" instead]
mprintf("During this 30s sleep, click on the figure\n  then on its menu ""Edit => Figure properties""")
// The graphical editor will be actually called only at wake-up
sleep(30, "s")

See also

  • pause — temporarily pauses the running execution, and allows instructions in console.
  • halt — stop execution


  • The fractional part of milliseconds is now accepted and processed.
  • Syntax sleep(seconds, "s") added.
Scilab Enterprises
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon Jan 03 14:23:29 CET 2022