enable the chief to access worker's total number of updates
| 175 | |
| 176 | |
| 177 | class Counter: |
| 178 | """enable the chief to access worker's total number of updates""" |
| 179 | |
| 180 | def __init__(self, val=True): |
| 181 | self.val = mp.Value("i", 0) |
| 182 | self.lock = mp.Lock() |
| 183 | |
| 184 | def get(self): |
| 185 | # used by chief |
| 186 | with self.lock: |
| 187 | return self.val.value |
| 188 | |
| 189 | def increment(self): |
| 190 | # used by workers |
| 191 | with self.lock: |
| 192 | self.val.value += 1 |
| 193 | |
| 194 | def reset(self): |
| 195 | # used by chief |
| 196 | with self.lock: |
| 197 | self.val.value = 0 |
| 198 | |
| 199 | # Get a render function |
| 200 | def get_render_func(venv): |