<commit_before>#!/usr/bin/env python3

import time, subprocess, platform, threading, queue
from collections import deque
from housepy import osc, util, log, config

class Health(threading.Thread):

    def __init__(self):
        threading.Thread.__init__(self)
        self.daemon = True
        self.sender = osc.Sender(config['controller'], 23232)
        self.queue = queue.Queue()
        self.start()        

    def run(self):
        while True:
            try:
                status = self.queue.get_nowait()
            except queue.Empty:
                status = "ready"
            self.sender.send("/health", [config['name'], status])
            time.sleep(config['health_rate'])

health = Health()            


class Player(threading.Thread):

    def __init__(self):
        threading.Thread.__init__(self)
        self.daemon = True
        self.queue = queue.Queue()
        self.process = None
        self.start()

    def run(self):
        while True:
            sound = self.queue.get()
            try:
                if platform.system() == "Darwin":
                    bn = "afplay"
                elif platform.system() == "Linux":
                    bn = "mpg123" if sound[-3:] == "mp3" else "aplay"
                self.process = subprocess.Popen([bn, 'snd/%s' % sound])
                health.queue.put('playing')
                # while True:
                #     if self.process.poll() is None:
                #         health.queue.put('playing')
                #         time.sleep(2)
                #     else:
                #         break                    
            except Exception as e:                
                log.error(log.exc(e))
                health.queue.put('playing failed')

    def stop(self):
        # this is not strictly thread-safe, is it?
        try:
            if self.process is not None:
                self.process.terminate()
                health.queue.put('stopped')
        except Exception as e:<commit_msg>untest<commit_after>#!/usr/bin/env python3

import time, subprocess, platform, threading, queue
from collections import deque
from housepy import osc, util, log, config

class Health(threading.Thread):

    def __init__(self):
        threading.Thread.__init__(self)
        self.daemon = True
        self.sender = osc.Sender(config['controller'], 23232)
        self.queue = queue.Queue()
        self.start()        

    def run(self):
        while True:
            try:
                status = self.queue.get_nowait()
            except queue.Empty:
                status = "ready"
            self.sender.send("/health", [config['name'], status])
            time.sleep(config['health_rate'])

health = Health()            


class Player(threading.Thread):

    def __init__(self):
        threading.Thread.__init__(self)
        self.daemon = True
        self.queue = queue.Queue()
        self.process = None
        self.start()

    def run(self):
        while True:
            sound = self.queue.get()
            try:
                if platform.system() == "Darwin":
                    bn = "afplay"
                elif platform.system() == "Linux":
                    bn = "mpg123" if sound[-3:] == "mp3" else "aplay"
                self.process = subprocess.Popen([bn, 'snd/%s' % sound])
                health.queue.put('playing')
                while True:
                    if self.process.poll() is None:
                        health.queue.put('playing')
                        time.sleep(2)
                    else:
                        break                    
            except Exception as e:                
                log.error(log.exc(e))
                health.queue.put('playing failed')

    def stop(self):
        # this is not strictly thread-safe, is it?
        try:
            if self.process is not None:
                self.process.terminate()
                health.queue.put('stopped')
        except Exception as e:
{'fraction_non_alphanumeric': 0.11175144074166876, 'fraction_numerical': 0.00601353044349787, 'mean_word_length': 1.4091732045866023, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5230501', 'n_tokens_mistral': 1109, 'n_tokens_neox': 1032, 'n_words': 251}