sleep is a system call that suspends a process or thread for a specified amount of time
Questions tagged [sleep]
3187 questions
97
votes
8 answers
How to make the script wait/sleep in a simple way in unity
How can I put a sleep function between the TextUI.text = ...., to wait 3 seconds between each phrase?
public Text GuessUI;
public Text TextUI;
[...truncated...]
TextUI.text = "Welcome to Number Wizard!";
TextUI.text = ("The highest number you can…

DiogoSaraiva
- 1,515
- 2
- 15
- 19
94
votes
4 answers
Python time.sleep() vs event.wait()
I want to perform an action at a regular interval in my multi-threaded Python application. I have seen two different ways of doing it
exit = False
def thread_func():
while not exit:
action()
time.sleep(DELAY)
or
exit_flag =…

AShelly
- 34,686
- 15
- 91
- 152
94
votes
4 answers
Java: Thread.currentThread().sleep(x) vs. Thread.sleep(x)
I have this in my code
Thread.currentThread().sleep(x);
Eclipse tells me to use the static
Thread.sleep(x);
instead, why? What's the difference, is there some difference in functionality at all between these 2 methods?

Omu
- 69,856
- 92
- 277
- 407
90
votes
13 answers
How do I create a pause/wait function using Qt?
I'm playing around with Qt, and I want to create a simple pause between two commands. However it won't seem to let me use Sleep(int mili);, and I can't find any obvious wait functions.
I am basically just making a console application to test some…

Zac
- 2,229
- 9
- 33
- 41
87
votes
7 answers
How to use nanosleep() in C? What are `tim.tv_sec` and `tim.tv_nsec`?
What is the use of tim.tv_sec and tim.tv_nsec in the following?
How can I sleep execution for 500000 microseconds?
#include
#include
int main()
{
struct timespec tim, tim2;
tim.tv_sec = 1;
tim.tv_nsec = 500;
…

pnizzle
- 6,243
- 4
- 52
- 81
87
votes
7 answers
How to sleep for few milliseconds in swift 2.2?
please anyone tell me how to use sleep() for few milliseconds in swift 2.2?
while (true){
print("sleep for 0.002 seconds.")
sleep(0.002) // not working
}
but
while (true){
print("sleep for 2 seconds.")
sleep(2) // working
}
it is…

sulabh qg
- 1,155
- 2
- 12
- 20
85
votes
6 answers
How do I sleep for a millisecond in Perl?
How do I sleep for shorter than a second in Perl?

ˈoʊ sɪks
- 897
- 1
- 7
- 10
85
votes
9 answers
How to get a unix script to run every 15 seconds?
I've seen a few solutions, including watch and simply running a looping (and sleeping) script in the background, but nothing has been ideal.
I have a script that needs to run every 15 seconds, and since cron won't support seconds, I'm left to…

Nick Sergeant
- 35,843
- 12
- 36
- 44
76
votes
5 answers
How to "sleep" until timeout or cancellation is requested in .NET 4.0
What's the best way to sleep a certain amount of time, but be able to be interrupted by a IsCancellationRequested from a CancellationToken?
I'm looking for a solution which works in .NET 4.0.
I'd like to write
void MyFunc (CancellationToken ct)
{
…

Onur
- 5,017
- 5
- 38
- 54
73
votes
13 answers
How to create a sleep/delay in nodejs that is Blocking?
I'm currently trying to learn nodejs and a small project I'm working is writing an API to control some networked LED lights.
The microprocessor controlling the LEDs has a processing delay, and I need to space commands sent to the micro at least…

on3al
- 2,090
- 4
- 20
- 19
72
votes
6 answers
Can any desktop browsers detect when the computer resumes from sleep?
It would be nice if the computer's 'wake up' event was propagated to the browser and available in the JavaScript API. Does anyone know if anything like this is implemented?

Zak Linder
- 1,016
- 1
- 9
- 13
72
votes
1 answer
Using async to sleep in a thread without freezing
So I a label here (""). When the button (button1) is clicked, the label text turns into "Test". After 2 seconds, the text is set back into "". I made this work with a timer (which has an interval of 2000):
private void button1_Click(object sender,…

jacobz
- 3,191
- 12
- 37
- 61
66
votes
5 answers
Does sleep time count for execution time limit?
I have two questions concerning the sleep() function in PHP:
Does the sleep time affect the maximum execution time limit of my PHP scripts? Sometimes, PHP shows the message "maximum execution time of 30 seconds exceeded". Will this message appear…

caw
- 30,999
- 61
- 181
- 291
65
votes
6 answers
Compare using Thread.Sleep and Timer for delayed execution
I have a method which should be delayed from running for a specified amount of time.
Should I use
Thread thread = new Thread(() => {
Thread.Sleep(millisecond);
action();
});
thread.IsBackground = true;
thread.Start();
Or
Timer timer = new…

Chaowlert Chaisrichalermpol
- 5,272
- 3
- 26
- 29
64
votes
18 answers
How to make thread sleep less than a millisecond on Windows
On Windows I have a problem I never encountered on Unix. That is how to get a thread to sleep for less than one millisecond. On Unix you typically have a number of choices (sleep, usleep and nanosleep) to fit your needs. On Windows, however, there…

Jorge Ferreira
- 96,051
- 25
- 122
- 132