Python time.sleep() vs event.wait()

Using exit_flag.wait(timeout=DELAY) will be more responsive, because you’ll break out of the while loop instantly when exit_flag is set. With time.sleep, even after the event is set, you’re going to wait around in the time.sleep call until you’ve slept for DELAY seconds. In terms of implementation, Python 2.x and Python 3.x have very different behavior. … Read more

Accurate Sleep for Java on Windows

To improve granularity of sleep you can try the following from this Thread.sleep page. Bugs with Thread.sleep() under Windows If timing is crucial to your application, then an inelegant but practical way to get round these bugs is to leave a daemon thread running throughout the duration of your application that simply sleeps for a … Read more

How do I create a pause/wait function using Qt?

I wrote a super simple delay function for an application I developed in Qt. I would advise you to use this code rather than the sleep function as it won’t let your GUI freeze. Here is the code: void delay() { QTime dieTime= QTime::currentTime().addSecs(1); while (QTime::currentTime() < dieTime) QCoreApplication::processEvents(QEventLoop::AllEvents, 100); } To delay an event … Read more

Sleep until a specific time/date

As mentioned by Outlaw Programmer, I think the solution is just to sleep for the correct number of seconds. To do this in bash, do the following: current_epoch=$(date +%s) target_epoch=$(date -d ’01/01/2010 12:00′ +%s) sleep_seconds=$(( $target_epoch – $current_epoch )) sleep $sleep_seconds To add precision down to nanoseconds (effectively more around milliseconds) use e.g. this syntax: … Read more

How to asynchronously wait for x seconds and execute something then?

(transcribed from Ben as comment) just use System.Windows.Forms.Timer. Set the timer for 5 seconds, and handle the Tick event. When the event fires, do the thing. …and disable the timer (IsEnabled=false) before doing your work in oder to suppress a second. The Tick event may be executed on another thread that cannot modify your gui, … Read more

asyncio.sleep() vs time.sleep() in Python

You aren’t seeing anything special because there’s nothing much asynchronous work in your code. However, the main difference is that time.sleep(5) is blocking, and asyncio.sleep(5) is non-blocking. When time.sleep(5) is called, it will block the entire execution of the script and it will be put on hold, just frozen, doing nothing. But when you call … Read more