<commit_before>import Queue
from pprint import pformat
from functools import total_ordering
from SocketServer import ThreadingTCPServer, BaseRequestHandler

from kuyruk.manager.messaging import message_loop


class ManagerServer(ThreadingTCPServer):

    daemon_threads = True

    def __init__(self, host, port):
        self.clients = {}
        ThreadingTCPServer.__init__(self, (host, port), RequestHandler)

    def get_request(self):
        client_sock, client_addr = ThreadingTCPServer.get_request(self)
        self.clients[client_addr] = ClientStruct(client_sock)
        print 'self.clients', pformat(self.clients)
        return client_sock, client_addr

    def process_request_thread(self, request, client_address):
        ThreadingTCPServer.process_request_thread(self, request,
                                                  client_address)
        self._remove_socket(client_address)

    def _remove_socket(self, client_address):
        del self.clients[client_address]
        print 'self.clients', pformat(self.clients)


class RequestHandler(BaseRequestHandler):

    def handle(self):
        try:
            message_loop(self.request, self._generate_action, self._on_stats)
        except EOFError:<commit_msg>manager: allow reuse address<commit_after>import Queue
from pprint import pformat
from functools import total_ordering
from SocketServer import ThreadingTCPServer, BaseRequestHandler

from kuyruk.manager.messaging import message_loop


class ManagerServer(ThreadingTCPServer):

    daemon_threads = True
    allow_reuse_address = True

    def __init__(self, host, port):
        self.clients = {}
        ThreadingTCPServer.__init__(self, (host, port), RequestHandler)

    def get_request(self):
        client_sock, client_addr = ThreadingTCPServer.get_request(self)
        self.clients[client_addr] = ClientStruct(client_sock)
        print 'self.clients', pformat(self.clients)
        return client_sock, client_addr

    def process_request_thread(self, request, client_address):
        ThreadingTCPServer.process_request_thread(self, request,
                                                  client_address)
        self._remove_socket(client_address)

    def _remove_socket(self, client_address):
        del self.clients[client_address]
        print 'self.clients', pformat(self.clients)


class RequestHandler(BaseRequestHandler):

    def handle(self):
        try:
            message_loop(self.request, self._generate_action, self._on_stats)
        except EOFError:
{'fraction_non_alphanumeric': 0.07290015847860538, 'fraction_numerical': 0.0, 'mean_word_length': 3.360967184801382, 'pattern_counts': {'":': 0, '<': 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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5252461', 'n_tokens_mistral': 704, 'n_tokens_neox': 694, 'n_words': 146}