<commit_before>import os
import sys
import json
import unittest
import time
import socketserver
import _thread

from hashlib import sha256


class MyRequestHandler(socketserver.StreamRequestHandler):
    """
    Request handler for testing metadisk.py.

    """

    def handle(self):
        """
        Temporary method, which response to "python metadisk.py files"
        command.
        :return: response with display of empty list
        """
        self.data = self.rfile.readline().strip()
        print("{} wrote:".format(self.client_address[0]))
        print(self.data)
        start_line = b'HTTP/1.0 200 OK\n'
        message = b'\n[]\n'
        headers = {
            'Content-Type': 'application/json',
            'Content-Length': len(message),
        }
        self.wfile.write(start_line)
        for line in sorted(headers.items()):
            self.wfile.write(bytes('%s: %s\n' % line, 'utf-8'))
        self.wfile.write(message)

    def finish(self):
        # You may run server like threading object and call shutdown from
        # the main program stream.

        # Temporary decision for shutdown server inside threading.
        self.server._BaseServer__shutdown_request = True


class MetadiskTest(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.metadisk_python_interpreter = sys.executable

    def setUp(self):
        HOST, PORT = 'localhost', 5000
        socketserver.TCPServer.allow_reuse_address = True
        server = socketserver.TCPServer((HOST, PORT), MyRequestHandler)
        _thread.start_new_thread(server.serve_forever, ())
        # delay for running server.
        time.sleep(2)

    @unittest.skip('yet unrealized action on server for this test')
    def test_info(self):
        with os.popen('%s metadisk.py info' %
                              self.metadisk_python_interpreter) as file:<commit_msg>chages: set correct threading logic<commit_after>import os
import sys
import json
import unittest
import socketserver
import threading

from hashlib import sha256


class MyRequestHandler(socketserver.StreamRequestHandler):
    """
    Request handler for testing metadisk.py.

    """

    def handle(self):
        """
        Temporary method, which response to "python metadisk.py files"
        command.
        :return: None
        """
        self.data = self.rfile.readline().strip()
        print("Received: {}".format(self.data))
        start_line = b'HTTP/1.0 200 OK\n'
        message = b'\n[]\n'
        headers = {
            'Content-Type': 'application/json',
            'Content-Length': len(message),
        }
        self.wfile.write(start_line)
        for line in sorted(headers.items()):
            self.wfile.write(bytes('%s: %s\n' % line, 'utf-8'))
        self.wfile.write(message)


class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
    pass



class MetadiskTest(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.metadisk_python_interpreter = sys.executable
        HOST, PORT = 'localhost', 5000
        ThreadedTCPServer.allow_reuse_address = True
        cls.server = ThreadedTCPServer((HOST, PORT), MyRequestHandler)

        server_thread = threading.Thread(target=cls.server.serve_forever)
        server_thread.daemon = True
        server_thread.start()


    def setUp(self):
        pass

    @classmethod
    def tearDownClass(cls):
        cls.server.shutdown()
        cls.server.server_close()

    @unittest.skip('yet unrealized action on server for this test')
    def test_info(self):
        with os.popen('%s metadisk.py info' %
                              self.metadisk_python_interpreter) as file:
{'fraction_non_alphanumeric': 0.10349498780818206, 'fraction_numerical': 0.007586020048767272, 'mean_word_length': 2.5128449096098953, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '460350', 'n_tokens_mistral': 1109, 'n_tokens_neox': 1076, 'n_words': 252}