<commit_before>import socket
import pigpio

pi = pigpio.pi()

bright = 255

RED_PIN   = 17
GREEN_PIN = 22
BLUE_PIN  = 24

serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversocket.bind(('192.168.0.234', 12345))
serversocket.listen(5) # become a server socket, maximum 5 connections

def setLights(pin, brightness):
        realBrightness = int(int(brightness) * (float(bright) / 255.0))
        pi.set_PWM_dutycycle(pin, realBrightness)

def setRGB(r,g,b):
        setLights(RED_PIN, r)
        setLights(GREEN_PIN, g)
        setLights(BLUE_PIN,b)

while True:
    connection, address = serversocket.accept()
    buf = connection.recv(64)
    if len(buf) > 0:
        aRGB = buf.split(',')
        if len(aRGB) == 3:
                r = int(aRGB[0])
                g = int(aRGB[1])
                b = int(aRGB[2])
                setRGB(r,g,b)

<commit_msg>Effects in Subprocesses<commit_after>import socket
import pigpio
import subprocess
import os
import signal
from subprocess import call
from subprocess import Popen, PIPE
import shlex

pi = pigpio.pi()

bright = 255

RED_PIN   = 17
GREEN_PIN = 22
BLUE_PIN  = 24

iCurrentPid = 0

def startProcess(path):
        process = subprocess.Popen(shlex.split(path), shell=False)
        return process.pid

def killProcess(processId):
        if processId:
                try:
                        os.kill(processId, signal.SIGTERM)
                except OSError:
                        print("UNABLE TO KILL: " + str(processId))
                        return False
                else:
                        return True

#START SOCKET
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversocket.bind(('192.168.0.234', 12345))
serversocket.listen(5) # become a server socket, maximum 5 connections

def setLights(pin, brightness):
        realBrightness = int(int(brightness) * (float(bright) / 255.0))
        pi.set_PWM_dutycycle(pin, realBrightness)

def setRGB(r,g,b):
        setLights(RED_PIN, r)
        setLights(GREEN_PIN, g)
        setLights(BLUE_PIN,b)

while True:
    connection, address = serversocket.accept()
    buf = connection.recv(64)
    if len(buf) > 0:

        #COPS EFFECT
        if buf == "COPS":
                killProcess(iCurrentPid)
                iCurrentPid = startProcess("python ./cops.py")

        aRGB = buf.split(',')
        if len(aRGB) == 3:
                killProcess(iCurrentPid)
                r = int(aRGB[0])
                g = int(aRGB[1])
                b = int(aRGB[2])
                setRGB(r,g,b)


{'fraction_non_alphanumeric': 0.10950332420805632, 'fraction_numerical': 0.02933124755572937, 'mean_word_length': 2.2297979797979797, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '6285128', 'n_tokens_mistral': 927, 'n_tokens_neox': 851, 'n_words': 188}