sleep is a system call that suspends a process or thread for a specified amount of time
Questions tagged [sleep]
3187 questions
3658
votes
92 answers
What is the JavaScript version of sleep()?
Is there a better way to engineer a sleep in JavaScript than the following pausecomp function (taken from here)?
function pausecomp(millis)
{
var date = new Date();
var curDate = null;
do { curDate = new Date(); }
while(curDate-date…

fmsf
- 36,317
- 49
- 147
- 195
3183
votes
13 answers
How do I make a time delay?
How do I put a time delay in a Python script?

user46646
- 153,461
- 44
- 78
- 84
1342
votes
33 answers
Difference between "wait()" vs "sleep()" in Java
What is the difference between a wait() and sleep() in Threads?
Is my understanding that a wait()-ing Thread is still in running mode and uses CPU cycles but a sleep()-ing does not consume any CPU cycles correct?
Why do we have both wait() and…

Geek
- 23,089
- 20
- 71
- 85
832
votes
19 answers
Sleep for milliseconds
I know the POSIX sleep(x) function makes the program sleep for x seconds. Is there a function to make the program sleep for x milliseconds in C++?

Prasanth Madhavan
- 12,657
- 15
- 62
- 94
760
votes
6 answers
How do I get my program to sleep for 50 milliseconds?
How do I get my Python program to sleep for 50 milliseconds?

TK.
- 46,577
- 46
- 119
- 147
567
votes
8 answers
How do I make a delay in Java?
I am trying to do something in Java and I need something to wait / delay for an amount of seconds in a while loop.
while (true) {
if (i == 3) {
i = 0;
}
ceva[i].setSelected(true);
// I need to wait here
…

ardb
- 6,075
- 5
- 14
- 16
499
votes
33 answers
How do I add a delay in a JavaScript loop?
I would like to add a delay/sleep inside a while loop:
I tried it like this:
alert('hi');
for(var start = 1; start < 10; start++) {
setTimeout(function () {
alert('hello');
}, 3000);
}
Only the first scenario is true: after showing…

olidev
- 20,058
- 51
- 133
- 197
479
votes
7 answers
Tell Ruby Program to Wait some amount of time
How do you tell a Ruby program to wait an arbitrary amount of time before moving on to the next line of code?

user94154
- 16,176
- 20
- 77
- 116
418
votes
7 answers
time.sleep -- sleeps thread or process?
In Python for *nix, does time.sleep() block the thread or the process?

Jeremy Dunck
- 5,724
- 6
- 25
- 30
417
votes
4 answers
Sleep Command in T-SQL?
Is there to way write a T-SQL command to just make it sleep for a period of time? I am writing a web service asynchronously and I want to be able to run some tests to see if the asynchronous pattern is really going to make it more scalable. In…

skb
- 30,624
- 33
- 94
- 146
381
votes
1 answer
JavaScript sleep/wait before continuing
I have a JavaScript code that I need to add a sleep/wait function to. The code I am running is already in a function, eg:
function myFunction(time)
{
alert('time starts now');
//code to make the program wait before continuing
alert('time…

user2370460
- 7,470
- 10
- 31
- 46
376
votes
3 answers
Difference between wait and sleep
What is difference between wait and sleep?

tirenweb
- 30,963
- 73
- 183
- 303
346
votes
13 answers
I get exception when using Thread.sleep(x) or wait()
I have tried to delay - or put to sleep - my Java program, but an error occurs.
I'm unable to use Thread.sleep(x) or wait(). The same error message appears:
unreported exception java.lang.InterruptedException; must be caught or declared to be…

vincent low
- 3,673
- 5
- 21
- 16
273
votes
9 answers
How to implement sleep function in TypeScript?
I'm developing a website in Angular 2 using TypeScript and I was wondering if there was a way to implement thread.sleep(ms) functionality.
My use case is to redirect the users after submitting a form after a few seconds which is very easy in…

kha
- 19,123
- 9
- 34
- 67
235
votes
12 answers
Bash: infinite sleep (infinite blocking)
I use startx to start X which will evaluate my .xinitrc. In my .xinitrc I start my window manager using /usr/bin/mywm. Now, if I kill my WM (in order to f.e. test some other WM), X will terminate too because the .xinitrc script reached EOF.
So I…

watain
- 4,838
- 4
- 34
- 35