-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwait.py
43 lines (31 loc) · 892 Bytes
/
wait.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from __future__ import division
from datetime import datetime
import time
def timestamp():
return int((datetime.utcnow() -
datetime(1970, 1, 1)).total_seconds() * 1000)
class wait:
last = None
step = 2000
def __init__(self, step):
self.start()
self.step = step
def start(self):
self.last = timestamp()
return self.last
def next(self):
if not self.last:
self.start()
waituntil = self.last + self.step
now = timestamp()
timetowait = waituntil - now # milliseconds
if timetowait > 0:
time.sleep(timetowait / 1000) # fractions of seconds
self.last = timestamp()
return self.last
if __name__ == '__main__':
w = wait(201)
initime = w.start()
print("started at: ", initime)
for k in range(3):
print(w.next())