forked from jashwanth0712/divide-n-conquer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dnq.py
66 lines (56 loc) · 2.18 KB
/
dnq.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from itertools import cycle
from shutil import get_terminal_size
from threading import Thread
from time import sleep
Logo="""
____ _ _ _
| _ \ (_) __ __ (_) __| | ___ _ __ ___ ___ _ __ __ _ _ _ ___ _ __
| | | | | | \ \ / / | | / _` | / _ \ _____ | '_ \ _____ / __| / _ \ | '_ \ / _` | | | | | / _ \ | '__|
| |_| | | | \ V / | | | (_| | | __/ |_____| | | | | |_____| | (__ | (_) | | | | | | (_| | | |_| | | __/ | |
|____/ |_| \_/ |_| \__,_| \___| |_| |_| \___| \___/ |_| |_| \__, | \__,_| \___| |_|
|_|
"""
print(Logo)
class Loader:
def __init__(self, desc="Loading...", end="Dataset1 recieved!", timeout=0.1):
self.desc = desc
self.end = end
self.timeout = timeout
self._thread = Thread(target=self._animate, daemon=True)
self.steps = ["⢿", "⣻", "⣽", "⣾", "⣷", "⣯", "⣟", "⡿"]
self.done = False
def start(self):
self._thread.start()
return self
def _animate(self):
for c in cycle(self.steps):
if self.done:
break
print(f"\r{self.desc} {c}", flush=True, end="")
sleep(self.timeout)
def __enter__(self):
self.start()
def stop(self):
self.done = True
cols = get_terminal_size((80, 20)).columns
print("\r" + " " * cols, end="", flush=True)
print(f"\r{self.end}", flush=True)
def __exit__(self, exc_type, exc_value, tb):
# handle exceptions with those variables ^
self.stop()
if __name__ == "__main__":
with Loader("Fetching Dataset1 ..."):
for i in range(10):
sleep(0.25)
print("Completed Dataset1 training")
for i in range(10):
sleep(0.25)
print("Deleted Dataset1")
loader = Loader("Fetching Dataset2", "Recieved Dataset 2!", 0.05).start()
for i in range(10):
sleep(0.25)
loader.stop()
loader = Loader("Training Dataset2", "Process completed", 0.05).start()
for i in range(10):
sleep(0.25)
loader.stop()