sleep

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

Python time.sleep() vs event.wait() Question: 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 = threading.Event() def thread_func(): while not exit_flag.wait(timeout=DELAY): action() Is there an advantage to one …

Total answers: 4

Display a countdown for the python sleep function

Display a countdown for the python sleep function Question: I am using time.sleep(10) in my program. Can display the countdown in the shell when I run my program? >>>run_my_program() tasks done, now sleeping for 10 seconds and then I want it to do 10,9,8,7…. is this possible? Asked By: user1681664 || Source Answers: you could …

Total answers: 12

Python, sleep some code not all

Python, sleep some code not all Question: I have a situation, where at some point in my code I want to trigger a number of timers, the code will keep running, but at some point these functions will trigger and remove an item from a given list. Similar though not exactly like the code below. …

Total answers: 3

Correct way to pause a Python program

Correct way to pause a Python program Question: 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? Asked By: RandomPhobia || Source Answers: It seems fine to me (or raw_input() in Python 2.X). Alternatively, you …

Total answers: 17

tkinter and time.sleep

tkinter and time.sleep Question: I am trying to delete text inside a text box after waiting 5 seconds, but instead the program wont run and does sleep over everything else. Also is there a way for me to just make my textbox sleep so i can run other code while the text is frozen? from …

Total answers: 2

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

How accurate is python's time.sleep()? Question: 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? Asked By: Claudiu || Source Answers: From the documentation: On the other hand, the precision of time() and sleep() is better than …

Total answers: 12

How do I get my program to sleep for 50 milliseconds?

How do I get my program to sleep for 50 milliseconds? Question: How do I get my Python program to sleep for 50 milliseconds? Asked By: TK. || Source Answers: Use time.sleep(): import time time.sleep(50 / 1000) See the Python documentation: https://docs.python.org/library/time.html#time.sleep Answered By: Dan Olson Use time.sleep() from time import sleep sleep(0.05) Answered By: …

Total answers: 6

time.sleep — sleeps thread or process?

time.sleep — sleeps thread or process? Question: In Python for *nix, does time.sleep() block the thread or the process? Asked By: Jeremy Dunck || Source Answers: Just the thread. Answered By: finnw It will just sleep the thread except in the case where your application has only a single thread, in which case it will …

Total answers: 7