<commit_before>#!/bin/python

import SocketServer
import time

STATE_DISCONNECTED = 0;
STATE_CONNECTED = 1;
STATE_RUNNING = 2;
STATE_STOPPED = 3;

class AccelerometerClient(object):
    def __init__(self, socket):
        self.state = STATE_CONNECTED
        self.events = list()
        self.socket = socket
        self.ip = socket.getpeername()[0]
    def addEvent(self, timestamp, x, y, z):
        event = { "timestamp" : timestamp, "x" : x, "y" : y, "z": z }
        self.events.append(event)

clients = dict()

class AccelerometerHandler(SocketServer.BaseRequestHandler):
  def handle(self):
    if not (self.request.getpeername()[0] in clients):
        self.client = AccelerometerClient(self.request)
        clients[self.client.ip] = self.client
        print "New client: " + str(self.client.ip)
    while True:
        self.data = self.request.recv(1024).strip()
        print "Client data " + self.data
        time.sleep(1)

if __name__ == "__main__":
  HOST, PORT = "192.168.0.101", 9999
  server = SocketServer.TCPServer((HOST, PORT), AccelerometerHandler)
  server.serve_forever()<commit_msg>Got threading working<commit_after>#!/bin/python

import SocketServer
import time
from threading import Thread
#from multiprocessing import Process

STATE_DISCONNECTED = 0;
STATE_CONNECTED = 1;
STATE_RUNNING = 2;
STATE_STOPPED = 3;

quit = False

class AccelerometerClient(object):
    def __init__(self, socket):
        self.state = STATE_CONNECTED
        self.events = list()
        self.socket = socket
        self.ip = socket.getpeername()[0]
    def addEvent(self, timestamp, x, y, z):
        event = { "timestamp" : timestamp, "x" : x, "y" : y, "z": z }
        self.events.append(event)

clients = dict()

class AccelerometerHandler(SocketServer.BaseRequestHandler):
  def handle(self):
    if not (self.request.getpeername()[0] in clients):
        self.client = AccelerometerClient(self.request)
        clients[self.client.ip] = self.client
        print "New client: " + str(self.client.ip)
    while not quit:
        self.data = self.request.recv(1024).strip()
        print "Client data " + self.data
        time.sleep(1)

def print_menu():
    print "(p)rint status"
    print "(s)ignal start"
    print "(h)alt data collection"
    print "(w)rite data to disk"
    print "(q)uit"

if __name__ == "__main__":
  HOST, PORT = "192.168.0.101", 9999
  server = SocketServer.TCPServer((HOST, PORT), AccelerometerHandler)
  t = Thread (target=server.serve_forever)
  t.start()
  quit = False
  try:
    while not quit:
      print_menu()
      choice = raw_input("Enter choice letter: ")
      if choice == "q":
          print "chose quit"
          quit = True
      else:
          print "didnt' choose quit"
    quit = True
    print "Calling server shutdown"
    server.shutdown()
    print "Joining thread"
    t.join()
    print "Goodbye!"
    raise KeyboardInterrupt()
  except KeyboardInterrupt:
    quit = True
    server.shutdown()
    t.join()
    print "Goodbye!"
{'fraction_non_alphanumeric': 0.12333333333333334, 'fraction_numerical': 0.016666666666666666, 'mean_word_length': 2.9853917662682603, 'pattern_counts': {'":': 5, '<': 3, '<?xml version=': 0, '>': 3, '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': '4970659', 'n_tokens_mistral': 1006, 'n_tokens_neox': 976, 'n_words': 245}