How to delay until a next increment of time occurs ?

David Raymond David.Raymond at tomtom.com
Wed Nov 13 14:06:34 EST 2019


I just used .perf_counter() as it's "a clock with the highest available resolution to measure a short duration"

The general simplified idea was run it whenever the time is 0 modulo your interval. So you ask how long until that next time.


Run whenever the time is 0 modulo .0003
Current time is 33.0143379
So I'm 0.0002379 into the cycle (33.0143379 % .0003)
And I've got .0000621 to sleep until the next mark (.0003 - .0002379)


-----Original Message-----
From: Python-list <python-list-bounces+david.raymond=tomtom.com at python.org> On Behalf Of R.Wieser
Sent: Wednesday, November 13, 2019 1:00 PM
To: python-list at python.org
Subject: Re: How to delay until a next increment of time occurs ?

David,

> timeInterval = 0.0003
> time.sleep(timeInterval - (time.perf_counter() % timeInterval))

Possibly: any reason for the performance counter modulo the interval ?

Regards,
Rudy Wieser


-- 
https://mail.python.org/mailman/listinfo/python-list


More information about the Python-list mailing list