Questions tagged [sleep]

sleep is a system call that suspends a process or thread for a specified amount of time

3187 questions
228
votes
17 answers

Correct way to pause a Python program

I've been using the input function as a way to pause my scripts: print("something") wait = input("Press Enter to continue.") print("something") Is there a formal way to do this?
RandomPhobia
  • 4,698
  • 7
  • 25
  • 22
204
votes
3 answers

Is there a Sleep/Pause/Wait function in JavaScript?

Is there a JavaScript function that simulates the operation of the sleep function in PHP — a function that pauses code execution for x milliseconds, and then resumes where it left off? I found some things here on Stack Overflow, but nothing useful.
richardaum
  • 6,651
  • 12
  • 48
  • 64
200
votes
5 answers

Is there an alternative sleep function in C to milliseconds?

I have some source code that was compiled on Windows. I am converting it to run on Red Hat Linux. The source code has included the header file and the programmer has used the Sleep() function to wait for a period of milliseconds. This…
ant2009
  • 27,094
  • 154
  • 411
  • 609
162
votes
15 answers

Sleep in JavaScript - delay between actions

Is there a way I can do a sleep in JavaScript before it carries out another action? Example: var a = 1 + 3; // Sleep 3 seconds before the next action here. var b = a + 4;
Jin Yong
  • 42,698
  • 72
  • 141
  • 187
155
votes
6 answers

What is the proper #include for the function 'sleep()'?

I am using the Big Nerd Ranch book Objective-C Programming, and it starts out by having us write in C in the first few chapters. In one of my programs it has me create, I use the sleep function. In the book it told me to put #include
trludt
  • 1,801
  • 2
  • 13
  • 15
154
votes
9 answers

Why is Thread.Sleep so harmful

I often see it mentioned that Thread.Sleep(); should not be used, but I can't understand why this is so. If Thread.Sleep(); can cause trouble, are there any alternative solutions with the same result that would be safe? eg. while(true) { …
Rosmarine Popcorn
  • 10,761
  • 11
  • 59
  • 89
131
votes
9 answers

How to keep a .NET console app running?

Consider a Console application that starts up some services in a separate thread. All it needs to do is wait for the user to press Ctrl+C to shut it down. Which of the following is the better way to do this? static ManualResetEvent _quitEvent =…
intoOrbit
  • 2,122
  • 2
  • 19
  • 21
131
votes
8 answers

When does Java's Thread.sleep throw InterruptedException?

When does Java's Thread.sleep throw InterruptedException? Is it safe to ignore it? I am not doing any multithreading. I just want to wait for a few seconds before retrying some operation.
Manki
  • 3,779
  • 4
  • 25
  • 18
123
votes
22 answers

Sleep until a specific time/date

I want my bash script to sleep until a specific time. So, I want a command like "sleep" which takes no interval but an end time and sleeps until then. The "at"-daemon is not a solution, as I need to block a running script until a certain…
theomega
  • 31,591
  • 21
  • 89
  • 127
122
votes
6 answers

What's the equivalent of Java's Thread.sleep() in Objective-C/Cocoa?

In Java you can suspend the current thread's execution for an amount of time using Thread.sleep(). Is there something like this in Objective-C?
levi
  • 2,035
  • 3
  • 16
  • 11
115
votes
2 answers

Thread.sleep vs. TimeUnit.SECONDS.sleep

If I'm going to have a call to have a Java Thread go to sleep, is there a reason to prefer one of these forms over the other? Thread.sleep(x) or TimeUnit.SECONDS.sleep(y)
Rachel
  • 2,181
  • 2
  • 18
  • 20
110
votes
2 answers

asyncio.sleep() vs time.sleep()

When I go to the asyncio page, the first example is a hello world program. When I run it on python 3.73, I can't see any different from the normal one. can anyone tell me the difference and give a non-trivial example? In [1]: import asyncio ...: …
an offer can't refuse
  • 4,245
  • 5
  • 30
  • 50
110
votes
13 answers

How accurate is python's time.sleep()?

I can give it floating point numbers, such as time.sleep(0.5) but how accurate is it? If i give it time.sleep(0.05) will it really sleep about 50 ms?
Claudiu
  • 224,032
  • 165
  • 485
  • 680
107
votes
2 answers

How and when to use SLEEP() correctly in MySQL?

In relation to my other question today I am wondering how to use MySQL's SLEEP(duration) correctly. From what I gathered reading MySQL Dev forums and very vague description in MySQL Docs I can't use it this way: SELECT ... SLEEP(1); /* wait for a…
Michal M
  • 9,322
  • 8
  • 47
  • 63
107
votes
7 answers

Timer & TimerTask versus Thread + sleep in Java

I found similar questions asked here but there weren't answers to my satisfaction. So rephrasing the question again- I have a task that needs to be done on a periodic basis (say 1 minute intervals). What is advantage of using Timertask & Timer to do…
Keshav
  • 4,408
  • 8
  • 31
  • 50