forked from nus-apr/auto-code-rover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_counter.py
47 lines (31 loc) · 1.28 KB
/
task_counter.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
"""
A global store, for values that cna be mutated in multiprocessing, along with their related values.
"""
import multiprocessing
# to be set at beginning
total_num_tasks = 0
num_completed_tasks = multiprocessing.Value("i", 0)
# to be set at beginning
total_num_task_groups = 0
num_completed_task_groups = multiprocessing.Value("i", 0)
def init_total_num_tasks(n: int):
global total_num_tasks
total_num_tasks = n
def init_total_num_task_groups(n: int):
global total_num_task_groups
total_num_task_groups = n
def incre_completed_tasks() -> int:
with num_completed_tasks.get_lock():
num_completed_tasks.value += 1
return num_completed_tasks.value
def incre_completed_task_groups() -> int:
with num_completed_task_groups.get_lock():
num_completed_task_groups.value += 1
return num_completed_task_groups.value
def incre_task_return_msg() -> str:
completed = incre_completed_tasks()
completed_groups = num_completed_task_groups.value
return f">>> Completed {completed}/{total_num_tasks} tasks. For groups, completed {completed_groups}/{total_num_task_groups} so far."
def incre_task_group_return_msg() -> str:
completed = incre_completed_task_groups()
return f">>>>>> Completed {completed}/{total_num_task_groups} task groups."