<commit_before>
import socket
from threading import Thread

class UDPListenerService(object):

    """ This class provides a simple server and client interface to send pings
    via the local network. It is mainly used to dynamically update the pipeline
    settings after they got changed by the various configurators. """

    CONFIG_PORT = 62324
    DAYTIME_PORT = 62325
    
    @staticmethod
    def do_ping(port, message="PING"):
        """ Sends a given message to a given port and immediately returns """
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        try:
            sock.sendto(message, ("127.0.0.1", port))
        finally:
            sock.shutdown(1)
            sock.close()

    @staticmethod
    def do_listen(port, callback):
        """ Listens to a given port, and calls callback in case a message
        arrives """
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        try:
            sock.bind(("127.0.0.1", port))

            while True:
                data, addr = sock.recvfrom(1024)
                callback(data)

        finally:
            sock.shutdown(1)
            sock.close()

    @classmethod
    def ping_thread(cls, port, message):
        """ Starts a new thread which sends a given message to a port """
        t = Thread(target=cls.do_ping, args=(port, message))
        t.start()

    @classmethod
    def listener_thread(cls, port, callback):
        """ Starts a new thread listening to the given port """
        t = Thread(target=cls.do_listen, args=(port, callback))
        t.start()
<commit_msg>Fix bug in listener service causing crashes<commit_after>#
import socket
from threading import Thread

class UDPListenerService(object):

    """ This class provides a simple server and client interface to send pings
    via the local network. It is mainly used to dynamically update the pipeline
    settings after they got changed by the various configurators. """

    CONFIG_PORT = 62324
    DAYTIME_PORT = 62325
    
    @staticmethod
    def do_ping(port, message="PING"):
        """ Sends a given message to a given port and immediately returns """
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        try:
            sock.sendto(message, ("127.0.0.1", port))
        finally:
            sock.close()

    @staticmethod
    def do_listen(port, callback):
        """ Listens to a given port, and calls callback in case a message
        arrives """
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        try:
            sock.bind(("127.0.0.1", port))
            while True:
                data, addr = sock.recvfrom(1024)
                callback(data)
        finally:
            sock.close()

    @classmethod
    def ping_thread(cls, port, message):
        """ Starts a new thread which sends a given message to a port """
        t = Thread(target=cls.do_ping, args=(port, message))
        t.start()

    @classmethod
    def listener_thread(cls, port, callback):
        """ Starts a new thread listening to the given port """
        t = Thread(target=cls.do_listen, args=(port, callback))
        t.start()

{'fraction_non_alphanumeric': 0.09559939301972686, 'fraction_numerical': 0.016995447647951443, 'mean_word_length': 2.3598369011213047, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '221108', 'n_tokens_mistral': 977, 'n_tokens_neox': 917, 'n_words': 300}