Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2024.1.0 - English


sleep

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

Syntax

sleep(milliseconds)
sleep(seconds, "s")

Arguments

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

Description

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

Console:
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.
callbacks:
.. 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.

Examples

// 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]
    tic;
    sleep(dt);
    dta = toc()*1000; // actual duration [ms]
    results = [results ; dt dta ];
end
results

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

// Test of interactions with menus:
clf
plot2d()
// [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

History

VersionDescription
6.0
  • The fractional part of milliseconds is now accepted and processed.
  • Syntax sleep(seconds, "s") added.
Report an issue
<< realtimeinit Time and Date tic >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon Jun 17 17:49:17 CEST 2024