Skip to content

Commit

Permalink
SIGUSR1 to idle, SIGUSR2 to activate
Browse files Browse the repository at this point in the history
  • Loading branch information
m0mchil committed Jan 21, 2013
1 parent 884ef27 commit d3e2fd5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
10 changes: 6 additions & 4 deletions Miner.py
@@ -1,6 +1,6 @@
from Queue import Queue
from decimal import Decimal
from threading import Thread, Lock
from threading import Thread
from time import time


Expand All @@ -19,7 +19,6 @@ def __init__(self, device_index, options):
self.rate = self.estimated_rate = 0

self.idle = True
self.idle_lock = Lock()

def start(self):
self.should_stop = False
Expand All @@ -45,6 +44,9 @@ def update_rate(self, now, iterations, t, targetQ, rate_divisor=1000):
self.estimated_rate = Decimal(self.estimated_rate) / 1000

self.switch.status_updated(self)

def toggle_idle(self):

def on_idle(self):
pass

def on_active(self):
pass
11 changes: 7 additions & 4 deletions OpenCLMiner.py
Expand Up @@ -135,10 +135,13 @@ def __init__(self, device_index, options):
if self.adapterIndex:
self.adapterIndex = self.adapterIndex[self.device_index].iAdapterIndex

def toggle_idle(self):
with self.idle_lock:
self.idle = not self.idle
say_line('%s is now %s', (self.id(), if_else(self.idle, 'idle', 'active')))
def on_idle(self):
self.idle = True
say_line('%s is now idle', (self.id()))

def on_active(self):
self.idle = False
say_line('%s is now active', (self.id()))

def id(self):
return str(self.options.platform) + ':' + str(self.device_index) + ':' + self.device_name
Expand Down
14 changes: 7 additions & 7 deletions poclbm.py
Expand Up @@ -71,16 +71,16 @@ def socketwrap(family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0):

switch = None

def sigusr1_handler(signum, frame):
raise KeyboardInterrupt

def sigusr2_handler(signum, frame):
def signal_handler(signum, frame):
if switch:
for miner in switch.miners:
miner.toggle_idle()
if signum == signal.SIGUSR1:
miner.on_idle()
elif signum == signal.SIGUSR2:
miner.on_active()

signal.signal(signal.SIGUSR1, sigusr1_handler)
signal.signal(signal.SIGUSR2, sigusr2_handler)
signal.signal(signal.SIGUSR1, signal_handler)
signal.signal(signal.SIGUSR2, signal_handler)

options.cutoff_temp = tokenize(options.cutoff_temp, 'cutoff_temp', [95], float)
options.cutoff_interval = tokenize(options.cutoff_interval, 'cutoff_interval', [0.01], float)
Expand Down

0 comments on commit d3e2fd5

Please sign in to comment.