im trying to write code that uses a for loop, it is meant to go through the first element in the array, wait 15 seconds, the run the second element. Is there any way to code that is pauses the for loop every 15 seconds? I have tried using .sleep but this freezes a timer I'm playing in the background which I need to have running. I have also tried using threading, but this restarts the function which then also restarts the for loop
Asked
Active
Viewed 65 times
1
-
When you say you tried using threading, did you try this? [Python Time Delays](https://stackoverflow.com/questions/3433559/python-time-delays) If it didn't work, please [edit] your question to show your code as a [mre] – Pranav Hosangadi Oct 14 '20 at 21:49
1 Answers
0
You're looking for time.sleep
.
import time
time.sleep(15)

Frank Yellin
- 9,127
- 1
- 12
- 22
-
i tried this, however, in the background I run a timer and when you use .sleep it freezes the timer aswell. apologies should've stated that. – Cameron McCusker Oct 14 '20 at 21:40
-
1In that case, I'm giving you the standard answer. Please show your code, what you've tried, and why you're not happy. So. . . . – Frank Yellin Oct 14 '20 at 21:42
-
If you're using threading.Timer and sleep() causes that not to work, you might also try sleeping for 1 second fifteen times. This will let the timer see if it can run once a second. That may be good enough for what you're trying to achieve. – Frank Yellin Oct 14 '20 at 21:48