<commit_before>import multiprocessing
import threading
import socket
import logging
import binascii

from synchrophasor.frame import *
from sys import stdout
from select import select
from time import sleep
from time import time

__author__ = "<NAME>"
__copyright__ = "Copyright (c) 2016, <NAME>, <NAME>, <NAME>"
__credits__ = []
__license__ = "GPL"
__version__ = "1.0"


class Pmu(object):

    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)

    handler = logging.StreamHandler(stdout)
    handler.setLevel(logging.DEBUG)
    formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
    handler.setFormatter(formatter)
    logger.addHandler(handler)

    def pmu_handler(self, connection, address, buffer):

        self.logger.info("[%d] - Connection from %s:%d", self.pmu_id, address[0], address[1])

        # Wait for start command from connected PDC/PMU to start sending
        sending_measurements_enabled = False

        # Calculate delay between data frames
        if self.data_rate > 0:
            delay = 1.0 / self.data_rate
        else:
            delay = self.data_rate

        try:
            while True:

                command = None
                readable, writable, exceptional = select([connection], [], [], 0)  # Check for client commands

                if readable:
                    data = connection.recv(self.buffer_size)  # TODO: Refactor this to recv_all

                    if data:
                        try:
                            received_message = CommonFrame.convert2frame(data)  # Try to decode received data

                            if isinstance(received_message, CommandFrame):
                                command = received_message.get_command()
                                self.logger.info("[%d] - Received command: [%s] <- (%s:%d)", self.pmu_id, command,
                                                 address[0], address[1])
                            else:
                                pass
                        except FrameError:
                            self.logger.warning("[%d] - Received unknown message <- (%s:%d)", self.pmu_id,
                                                address[0], address[1])
                if command == 'start':
                    sending_measurements_enabled = True
                    self.logger.info("[%d] - Start sending -> (%s:%d)", self.pmu_id, address[0], address[1])

                elif command == 'stop':
                    self.logger.info("[%d] - Stop sending -> (%s:%d)", self.pmu_id, address[0], address[1])
                    break
                elif command == 'header':
                    connection.sendall(self.header.convert2bytes())
                    self.logger.info("[%d] - Requested Header frame sent -> (%s:%d)",
                                     self.pmu_id, address[0], address[1])
                elif command == 'cfg1':
                    connection.sendall(self.cfg1.convert2bytes())
                    self.logger.info("[%d] - Requested Configuration frame 1 sent -> (%s:%d)", self.pmu_id,
                                     address[0], address[1])
                elif command == 'cfg2':
                    connection.sendall(self.cfg2.convert2bytes())
                    self.logger.info("[%d] - Requested Configuration frame 2 sent -> (%s:%d)", self.pmu_id,
                                     address[0], address[1])
                elif command == 'cfg3':
                    connection.sendall(self.cfg3.convert2bytes())
                    self.logger.info("[%d] - Requested Configuration frame 3 sent -> (%s:%d)", self.pmu_id,
                                     address[0], address[1])

                if sending_measurements_enabled and not buffer.empty():
                    sleep(delay)
                    connection.sendall(buffer.get())
                    self.logger.debug("[%d] - Message sent at [%f] -> (%s:%d)", self.pmu_id, time(), address[0],
                                      address[1])  # TODO: Remove this for better performance

        except Exception as e:
            print(e)
        finally:
            connection.close()
            self.client_buffers.remove(buffer)
            self.logger.info("[%d] - Connection from %s:%d has been closed.", self.pmu_id, address[0], address[1])

    def join(self):<commit_msg>do not close just stop sending<commit_after>import multiprocessing
import threading
import socket
import logging
import binascii

from synchrophasor.frame import *
from sys import stdout
from select import select
from time import sleep
from time import time

__author__ = "<NAME>"
__copyright__ = "Copyright (c) 2016, <NAME>, <NAME>, <NAME>"
__credits__ = []
__license__ = "GPL"
__version__ = "1.0"


class Pmu(object):

    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)

    handler = logging.StreamHandler(stdout)
    handler.setLevel(logging.DEBUG)
    formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
    handler.setFormatter(formatter)
    logger.addHandler(handler)

    def pmu_handler(self, connection, address, buffer):

        self.logger.info("[%d] - Connection from %s:%d", self.pmu_id, address[0], address[1])

        # Wait for start command from connected PDC/PMU to start sending
        sending_measurements_enabled = False

        # Calculate delay between data frames
        if self.data_rate > 0:
            delay = 1.0 / self.data_rate
        else:
            delay = self.data_rate

        try:
            while True:

                command = None
                readable, writable, exceptional = select([connection], [], [], 0)  # Check for client commands

                if readable:
                    data = connection.recv(self.buffer_size)  # TODO: Refactor this to recv_all

                    if data:
                        try:
                            received_message = CommonFrame.convert2frame(data)  # Try to decode received data

                            if isinstance(received_message, CommandFrame):
                                command = received_message.get_command()
                                self.logger.info("[%d] - Received command: [%s] <- (%s:%d)", self.pmu_id, command,
                                                 address[0], address[1])
                            else:
                                pass
                        except FrameError:
                            self.logger.warning("[%d] - Received unknown message <- (%s:%d)", self.pmu_id,
                                                address[0], address[1])
                if command == 'start':
                    sending_measurements_enabled = True
                    self.logger.info("[%d] - Start sending -> (%s:%d)", self.pmu_id, address[0], address[1])

                elif command == 'stop':
                    self.logger.info("[%d] - Stop sending -> (%s:%d)", self.pmu_id, address[0], address[1])
                    sending_measurements_enabled = False
                    # break
                elif command == 'header':
                    connection.sendall(self.header.convert2bytes())
                    self.logger.info("[%d] - Requested Header frame sent -> (%s:%d)",
                                     self.pmu_id, address[0], address[1])
                elif command == 'cfg1':
                    connection.sendall(self.cfg1.convert2bytes())
                    self.logger.info("[%d] - Requested Configuration frame 1 sent -> (%s:%d)", self.pmu_id,
                                     address[0], address[1])
                elif command == 'cfg2':
                    connection.sendall(self.cfg2.convert2bytes())
                    self.logger.info("[%d] - Requested Configuration frame 2 sent -> (%s:%d)", self.pmu_id,
                                     address[0], address[1])
                elif command == 'cfg3':
                    connection.sendall(self.cfg3.convert2bytes())
                    self.logger.info("[%d] - Requested Configuration frame 3 sent -> (%s:%d)", self.pmu_id,
                                     address[0], address[1])

                if sending_measurements_enabled and not buffer.empty():
                    sleep(delay)
                    connection.sendall(buffer.get())
                    self.logger.debug("[%d] - Message sent at [%f] -> (%s:%d)", self.pmu_id, time(), address[0],
                                      address[1])  # TODO: Remove this for better performance

        except Exception as e:
            print(e)
        finally:
            connection.close()
            self.client_buffers.remove(buffer)
            self.logger.info("[%d] - Connection from %s:%d has been closed.", self.pmu_id, address[0], address[1])

    def join(self):
{'fraction_non_alphanumeric': 0.11451942740286299, 'fraction_numerical': 0.010452169961372415, 'mean_word_length': 1.602897693672383, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6397558', 'n_tokens_mistral': 2336, 'n_tokens_neox': 2217, 'n_words': 556}