-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobals.py
More file actions
72 lines (60 loc) · 2 KB
/
Copy pathglobals.py
File metadata and controls
72 lines (60 loc) · 2 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from threading import Semaphore
from termcolor import colored
def print_cpu_cores_consumed_time(cpu_cores):
print()
print(colored('.: CPU Cores Status :.', 'yellow', attrs=('bold', )))
for core in cpu_cores:
print(colored(core.name + ': ', 'yellow') + str(core.idle_time) + ' secs!')
print(colored('Total CPU time: ', 'yellow') + str(get_system_total_time()) + ' secs!')
print()
def print_system_status(cpu_cores, resources):
print()
print(colored('.: System Status :.', 'yellow', attrs=('bold', )))
cpu_core_mutex.acquire(blocking=False)
for core in cpu_cores:
print(colored(core.name + ':', 'yellow'), end=' ')
if core.get_state() == 'idle':
print('idle')
else:
print(core.running_task.name)
cpu_core_mutex.release()
resource_mutex.acquire(blocking=False)
for res, cnt in resources.items():
print(colored('Resource ' + res + ': ', 'yellow') + str(cnt))
print()
resource_mutex.release()
def increment_system_total_time():
global system_total_time
system_total_time_mutex.acquire(blocking=False)
system_total_time += 1
system_total_time_mutex.release()
def get_system_total_time():
system_total_time_mutex.acquire(blocking=False)
time = system_total_time
system_total_time_mutex.release()
return time
def join_threads(threads):
for th in threads:
if th.is_alive():
th.join()
def get_done_tasks_count(tasks):
global task_mutex
done_tasks_count = 0
for task in tasks:
task_mutex.acquire(blocking=False)
if task.state == 'done':
done_tasks_count += 1
task_mutex.release()
return done_tasks_count
if __name__ == 'globals':
resource_mutex = Semaphore()
task_mutex = Semaphore()
cpu_core_mutex = Semaphore()
system_total_time_mutex = Semaphore()
system_total_time_mutex.acquire()
ready = []
waiting = []
cpu_cores = []
resources = {}
tasks = []
system_total_time = 0