python - Real time timer -
i new python gentle.
i have been trying write program counts or measures events in real time. @ moment using sleep command pause event doesn't take account time program takes run. have read on datetime
module , can sort of see how used, bit stuck in implementing this.
in short, want program counts 0 100 in real time seconds , milliseconds.
your best bet (besides googling before posting question on so) might this:
- note time when program starts.
start = datetime.datetime.now()
- do calculations
sleep
until 100 seconds afterstart
. (start + datetime.timedelta(seconds=100)
)- note won't perfect, since there little overhead involved steps between accessing "current time" , going "sleep" (e.g. subtracting "current time" "wake-up time"). however, if sleep precision needs in seconds, should okay.
- repeat needed.
if, after trying out, need additional actual implementation of these steps, feel free come , post question on topic.
Comments
Post a Comment