Reputation:
def countdown(t):
while t > 0:
print(t)
t = t-1
time.sleep(1.0)
if t == 0:
print('blast off')
T=20
So this timer works well. It does what it needs, it counts which is what I want. But when it ends it stops my program I'm running it with and does a Timeouterror. Is there a countdown that won't do this or something I can add to it?
Upvotes: 0
Views: 169
Reputation: 638
You mentioned both that this was a background task, and that this causes a TimeoutError
. That's because D.py runs asyncio, and time.sleep
is blocking, meaning that it stops all threads running while it processes. What you want is the async-friendly version, await asyncio.sleep(1.0)
instead of time.sleep(1.0)
.
Upvotes: 0