-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRedditThread.py
44 lines (37 loc) · 1.23 KB
/
RedditThread.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
#!/usr/bin/env python2.7
import threading
import CentralScrutinizer
import Policies
class RedditThread(object):
"""
A class designed to be used as a thread in the Central Scrutinizer
takes care of some basics such as pausing / exiting etc.
:type owner: CentralScrutinizer.CentralScrutinizer
:type policy: Policies.DefaultPolicy
"""
def __init__(self, owner, policy):
self.owner = owner
self.policy = policy
self.wait = threading.Event()
self.exit = threading.Event()
self.instances = [0 for i in range(policy.Errors_Before_Halt)]
def check_status(self):
#push back an instance
self.instances.insert(0, 0)
self.instances = self.instances[:self.policy.Errors_Before_Halt]
#check for pause
while self.wait.is_set():
self.wait.wait(self.policy.Pause_Period)
#check for exit
if self.exit.is_set():
self.shutdown()
return False
return True
def shutdown(self):
pass
def log_error(self):
self.instances[0] = 1
if sum(self.instances) == self.policy.Errors_Before_Halt:
self.owner.request_pause()
def run(self):
raise NotImplementedError