sleep

Python stops unexpectedly after 1 minute

Python stops unexpectedly after 1 minute Question: My Python program stops functioning after exactly 1 minute. Regardless of the code’s size, the program stops after exactly 1 minute. Here is some very simple code: import time seconds = 60 print(f"Trying to print ‘Hello’. Wait {seconds} seconds.") for second in range(1,seconds): time.sleep(1) print(f"{second}…") print("Hello") It first …

Total answers: 2

Python How to sleep until a specific timestamp "DD-MM-YYYY HH:MM:SS"

Python How to sleep until a specific timestamp "DD-MM-YYYY HH:MM:SS" Question: So I have the following timestamp: 23-03-2023 10:11:00 How is it possible in python to sleep from the current time until the timestamp while printing the remaining time in hours-minutes-seconds? I don’t get quiet the logic of all the different timestamp formats. I have …

Total answers: 2

Is there a more precise alternative to time.sleep() in Python?

Is there a more precise alternative to time.sleep() in Python? Question: So I was looking for a more precise alternative to time.sleep() in Python but couldn’t find any good options. Does anyone know if there is a more accurate alternative with at least millisecond precision? Something like this: precise_delay(3.141) # Pauses the program for exactly …

Total answers: 2

Optimising Python script for scraping to avoid getting blocked/ draining resources

Optimising Python script for scraping to avoid getting blocked/ draining resources Question: I have a fairly basic Python script that scrapes a property website, and stores the address and price in a csv file. There are over 5000 listings to go through but I find my current code times out after a while (about 2000 …

Total answers: 1

Is there a better way to display a simple countdown or is this good enough?

Is there a better way to display a simple countdown or is this good enough? Question: Today I learned the time.sleep function and tried to create a countdown from it. At first I had made it very complicated (see python comment) and then I found a much better, simpler method. Now I’m thirsty for knowledge …

Total answers: 1

Does Python code run when computer is sleeping?

Does Python code run when computer is sleeping? Question: I have an unusual question.. Does Python code run when computer is sleeping? Thank you for help! Asked By: traiz || Source Answers: Check your computer’s "Power Options" in the Control panel. You don’t need to worry about the screen locking because as long as the …

Total answers: 2

How to program a task with a timer in my Python code?

How to program a task with a timer in my Python code? Question: I want to execute a task after certain time, so I have tried a countdown timer with a condition of being finished (when countdown variable = 0, the task is performed). The thing is that I don’t want to stop the execution …

Total answers: 3

Should we be using time.sleep() or sleep()?

Should we be using time.sleep() or sleep()? Question: I have heard that using sleep() in python is more appropriate than using time.sleep(). If so, why and where is one more appropriate than the other one? (Is one more appropriate than the other or is it just the same? – without opinions – only fact.) P.S. …

Total answers: 2

How to make a delay at ~100-200us

How to make a delay at ~100-200us Question: I would like to try some hardware testing with python. I have to send commands to the hardware where there is a specification for consecutive bytes transmission time interval (~100-200us). However, I found the sleep() method in time module unstable when the delay time is too small. …

Total answers: 3

Python 3.6 sleep() different sleep times within same string depending on character

Python 3.6 sleep() different sleep times within same string depending on character Question: In python 3.6, I’m trying to get a string to print with a delay between characters and a longer delay for punctuation at the end of sentences to pseudo-simulate spoken English. Here is my code. My problem is that I get the …

Total answers: 3