<commit_before>import os
import sys
import settings
import traceback
import threading
import Queue
import crystal_helpers as crystal

BASE_PATH = os.path.dirname(os.path.realpath(__file__))
UPPER_PATH = os.path.split(os.path.dirname(os.path.realpath(__file__)))[0]
DEVICES_PATH = "%s/Hosts/" % (BASE_PATH )
THIRTYBIRDS_PATH = "%s/thirtybirds_2_0" % (UPPER_PATH )

sys.path.append(BASE_PATH)
sys.path.append(UPPER_PATH)

from thirtybirds_2_0.Network.manager import init as network_init

class GainRampThread(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.currentGains = [0x00, 0x00, 0x00]
        self.targetGains = [0x00, 0x00, 0x00]
        self.rampTimePerIncrement = 0.001
        self.queue = Queue.Queue()

    def setRampTime(self, r):
        self.rampTimePerIncrement = r

    def setTargetGain(self, crystalIndex, gain):
        print "setTargetGain", crystalIndex, gain
        self.queue.put((crystalIndex, gain))

    def run(self):
        while True:
            #print "self.queue.empty()", self.queue.empty()
            print "----> 0"#, self.queue.get(False)
            #while not self.queue.empty():
            #    crystalIndex, gain = self.queue.get()
            #    self.targetGains[crystalIndex] = gain & 0xFF
            for i in range(0, 3):
                print "----> 1"
                if (self.targetGains[i] > self.currentGains[i]):
                    print "----> 2"
                    self.currentGains[i] = self.currentGains[i] + 1
                    print "----> 3"
                    print "GainRampThread", i, self.currentGains[i]
                    print "----> 4"
                    crystal.set_volume(i, self.currentGains[i])
                    print "----> 5"
                elif (self.targetGains[i] < self.currentGains[i]):
                    print "----> 6"
                    self.currentGains[i] = self.currentGains[i] - 1
                    print "----> 7"
                    print "GainRampThread", i, self.currentGains[i]
                    print "----> 8"
                    crystal.set_volume(i, self.currentGains[i])
                    print "----> 9"
            time.sleep(0.01)
            print "----> 10"

class Network(object):
    def __init__(self, hostname, network_message_handler, network_status_handler):
        self.hostname = hostname
        self.thirtybirds = network_init(
            hostname=hostname,
            role="client",
            discovery_multicastGroup=settings.discovery_multicastGroup,
            discovery_multicastPort=settings.discovery_multicastPort,
            discovery_responsePort=settings.discovery_responsePort,
            pubsub_pubPort=settings.pubsub_pubPort,
            message_callback=network_message_handler,
            status_callback=network_status_handler
        )


# Main handles network send/recv and can see all other classes directly
class Main(threading.Thread):
    def __init__(self, hostname):
        threading.Thread.__init__(self)
        self.network = Network(hostname, self.network_message_handler, self.network_status_handler)
        self.queue = Queue.Queue()
        self.gainRampThread = GainRampThread()
        self.gainRampThread.daemon = True
        self.gainRampThread.start()
        #self.gainRampThread = gainRampThread<commit_msg>troubleshooting thread queue<commit_after>
import crystal_helpers as crystal
import os
import Queue
import sys
import settings
import time
import traceback
import threading

BASE_PATH = os.path.dirname(os.path.realpath(__file__))
UPPER_PATH = os.path.split(os.path.dirname(os.path.realpath(__file__)))[0]
DEVICES_PATH = "%s/Hosts/" % (BASE_PATH )
THIRTYBIRDS_PATH = "%s/thirtybirds_2_0" % (UPPER_PATH )

sys.path.append(BASE_PATH)
sys.path.append(UPPER_PATH)

from thirtybirds_2_0.Network.manager import init as network_init

class GainRampThread(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.currentGains = [0x00, 0x00, 0x00]
        self.targetGains = [0x00, 0x00, 0x00]
        self.rampTimePerIncrement = 0.001
        self.queue = Queue.Queue()

    def setRampTime(self, r):
        self.rampTimePerIncrement = r

    def setTargetGain(self, crystalIndex, gain):
        print "setTargetGain", crystalIndex, gain
        self.queue.put((crystalIndex, gain))

    def run(self):
        while True:
            #print "self.queue.empty()", self.queue.empty()
            print "----> 0"#, self.queue.get(False)
            #while not self.queue.empty():
            #    crystalIndex, gain = self.queue.get()
            #    self.targetGains[crystalIndex] = gain & 0xFF
            for i in range(0, 3):
                print "----> 1"
                if (self.targetGains[i] > self.currentGains[i]):
                    print "----> 2"
                    self.currentGains[i] = self.currentGains[i] + 1
                    print "----> 3"
                    print "GainRampThread", i, self.currentGains[i]
                    print "----> 4"
                    crystal.set_volume(i, self.currentGains[i])
                    print "----> 5"
                elif (self.targetGains[i] < self.currentGains[i]):
                    print "----> 6"
                    self.currentGains[i] = self.currentGains[i] - 1
                    print "----> 7"
                    print "GainRampThread", i, self.currentGains[i]
                    print "----> 8"
                    crystal.set_volume(i, self.currentGains[i])
                    print "----> 9"
            time.sleep(rampTimePerIncrement)
            print "----> 10"

class Network(object):
    def __init__(self, hostname, network_message_handler, network_status_handler):
        self.hostname = hostname
        self.thirtybirds = network_init(
            hostname=hostname,
            role="client",
            discovery_multicastGroup=settings.discovery_multicastGroup,
            discovery_multicastPort=settings.discovery_multicastPort,
            discovery_responsePort=settings.discovery_responsePort,
            pubsub_pubPort=settings.pubsub_pubPort,
            message_callback=network_message_handler,
            status_callback=network_status_handler
        )


# Main handles network send/recv and can see all other classes directly
class Main(threading.Thread):
    def __init__(self, hostname):
        threading.Thread.__init__(self)
        self.network = Network(hostname, self.network_message_handler, self.network_status_handler)
        self.queue = Queue.Queue()
        self.gainRampThread = GainRampThread()
        self.gainRampThread.daemon = True
        self.gainRampThread.start()
        #self.gainRampThread = gainRampThread
{'fraction_non_alphanumeric': 0.11106155218554861, 'fraction_numerical': 0.01352958667856081, 'mean_word_length': 2.1567339277334585, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '483240', 'n_tokens_mistral': 2114, 'n_tokens_neox': 2009, 'n_words': 372}