<commit_before>import socket
import time

from rlbot.agents.base_independent_agent import BaseIndependentAgent
from rlbot.utils.logging_utils import get_logger


class BaseDotNetAgent(BaseIndependentAgent):

    def __init__(self, name, team, index):
        self.name = name
        self.team = team
        self.index = index

    def run_independently(self, terminate_request_event):

        while not terminate_request_event.is_set():
            port = self.read_port_from_file()
            message = "add {0} {1} {2}".format(self.name, self.team, self.index)

            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.connect(("127.0.0.1", port))
            s.send(bytes(message, "ASCII"))
            s.close()

            time.sleep(1)
        else:
            self.retire()

    def retire(self):
        port = self.read_port_from_file()
        message = "remove {0}".format(self.index)

        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect(("127.0.0.1", port))
        s.send(bytes(message), "ASCII")
        s.close()
    
    def read_port_from_file(self):
        try:
            location = self.get_port_file_path()

            with open(location, "r") as port_file:
                return int(port_file.readline().rstrip())

        except ValueError:
            self.logger.warn("Failed to parse port file!")
            raise

    def get_port_file_path(self):
        raise NotImplementedError<commit_msg>Fixing socket bug in base_dotnet_agent.py<commit_after>import socket
import time

from rlbot.agents.base_independent_agent import BaseIndependentAgent
from rlbot.utils.logging_utils import get_logger


class BaseDotNetAgent(BaseIndependentAgent):

    def __init__(self, name, team, index):
        self.name = name
        self.team = team
        self.index = index

    def run_independently(self, terminate_request_event):

        while not terminate_request_event.is_set():
            port = self.read_port_from_file()
            message = "add {0} {1} {2}".format(self.name, self.team, self.index)

            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.connect(("127.0.0.1", port))
            s.send(bytes(message, "ASCII"))
            s.close()

            time.sleep(1)
        else:
            self.retire()

    def retire(self):
        port = self.read_port_from_file()
        message = "remove {0}".format(self.index)

        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect(("127.0.0.1", port))
        s.send(bytes(message, "ASCII"))
        s.close()
    
    def read_port_from_file(self):
        try:
            location = self.get_port_file_path()

            with open(location, "r") as port_file:
                return int(port_file.readline().rstrip())

        except ValueError:
            self.logger.warn("Failed to parse port file!")
            raise

    def get_port_file_path(self):
        raise NotImplementedError
{'fraction_non_alphanumeric': 0.1106283422459893, 'fraction_numerical': 0.011363636363636364, 'mean_word_length': 2.303532008830022, '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': '408819', 'n_tokens_mistral': 955, 'n_tokens_neox': 910, 'n_words': 183}