#๐ How do I pause execution for a given time (like sleep()) but taking into account execution time?
29 messages ยท Page 1 of 1 (latest)
@spare mango
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
you can use time.time() to note down the time at the start and end of the process
ooh
then subtract that from 1 second, and sleep for that amount
:white_check_mark: Your 3.12 eval job has completed with return code 0.
1728833280.607594
exactly
but that isn't necessarily important
you just need to get the difference of 2 different time.time() calls
!e
import time
start = time.time()
time.sleep(1)
end = time.time()
print(f"The process took {end - start:.2f} seconds")
:white_check_mark: Your 3.12 eval job has completed with return code 0.
The process took 1.00 seconds
sounds like a task for https://docs.python.org/3/library/threading.html#timer-objects
yeah, I just didn't know if I had to seperate out milliseconds or something. But no, we're good
how so?
I've gotten a good answer, let's see if this can top it lol
Timer calls your function after a given time
maybe not the best fit to use threads tho, idk
I may need threading for performance later in my code, I'll check it out.
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.