Permalink
Browse files

SIGUSR1 to idle, SIGUSR2 to activate

  • Loading branch information...
1 parent 884ef27 commit d3e2fd5a45f43ab91efcfb5eb220a364f141a7ab @m0mchil committed Jan 21, 2013
Showing with 20 additions and 15 deletions.
  1. +6 −4 Miner.py
  2. +7 −4 OpenCLMiner.py
  3. +7 −7 poclbm.py
View
10 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
@@ -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
@@ -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
View
11 OpenCLMiner.py
@@ -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
View
14 poclbm.py
@@ -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)

0 comments on commit d3e2fd5

Please sign in to comment.