-
Notifications
You must be signed in to change notification settings - Fork 255
Expand file tree
/
Copy pathsync_prod.py
More file actions
48 lines (34 loc) · 1.13 KB
/
sync_prod.py
File metadata and controls
48 lines (34 loc) · 1.13 KB
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
44
45
46
47
48
import datetime
import random
import time
import colorama
def main():
t0 = datetime.datetime.now()
print(colorama.Fore.WHITE + 'App started.', flush=True)
data = []
generate_data(20, data)
generate_data(20, data)
process_data(40, data)
dt = datetime.datetime.now() - t0
print(colorama.Fore.WHITE + f'App exiting, total time: {dt.total_seconds():,.2f} sec.', flush=True)
def generate_data(num: int, data: list):
for idx in range(1, num + 1):
item = idx * idx
data.append((item, datetime.datetime.now()))
print(colorama.Fore.YELLOW + f' -- generated item {idx}', flush=True)
time.sleep(random.random() + 0.5)
def process_data(num: int, data: list):
processed = 0
while processed < num:
item = data.pop(0)
if not item:
time.sleep(0.01)
continue
processed += 1
value = item[0]
t = item[1]
dt = datetime.datetime.now() - t
print(colorama.Fore.CYAN + f' +++ Processed value {value} after {dt.total_seconds():,.2f} sec.', flush=True)
time.sleep(0.5)
if __name__ == '__main__':
main()