<commit_before>import os
import time
import fcntl

try:
    ProcessLookupError
except NameError:
    ProcessLookupError = OSError


class ProcessesManager:
    """
        Object that sinchronizes multiple adaptivePELE instances, designed to
        be able to use multiple nodes of a gpu cluster
    """
    RUNNING = "RUNNING"
    WAITING = "WATING"
    INIT = "INIT"

    def __init__(self, output_path):
        self.lockFile = os.path.join(output_path, "syncFile.lock")
        self.pid = os.getpid()
        self.id = None
        self.lockInfo = {}
        self.status = self.INIT
        self.createLockFile()

    def __len__(self):
        # define the size of the ProcessesManager object as the number of
        # processes
        return len(self.lockInfo)

    def createLockFile(self):
        """
            Create the lock file and write the information for the current
            process
        """
        if not os.path.exists(self.lockFile):
            # create file
            with open(self.lockFile, "w") as fw:
                # write something so that the file is created, it will be later
                # overwritten
                fw.write("0\n")
        file_lock = open(self.lockFile, "r+")
        while True:
            # loop until a lock can be aqcuired
            try:
                # get lock
                fcntl.lockf(file_lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
                break
            except (IOError, OSError):
                time.sleep(2)
        self.lockInfo = self.getLockInfo(file_lock)
        if len(self.lockInfo):
            self.id = len(self.lockInfo)
        else:
            self.id = 0
        self.lockInfo[self.pid] = (self.id, self.status)
        self.writeLockInfo(file_lock)
        fcntl.lockf(file_lock, fcntl.LOCK_UN)
        file_lock.close()

    def getLockInfo(self, file_descriptor):
        """
            Return the info stored in the lock file

            :param file_descriptor: File object of the lock file
            :type file_descriptor: file

            :returns: dict -- A dictonary containing the information of the<commit_msg>Create the lock always when the object is created<commit_after>import os
import time
import fcntl

try:
    ProcessLookupError
except NameError:
    ProcessLookupError = OSError


class ProcessesManager:
    """
        Object that sinchronizes multiple adaptivePELE instances, designed to
        be able to use multiple nodes of a gpu cluster
    """
    RUNNING = "RUNNING"
    WAITING = "WATING"
    INIT = "INIT"

    def __init__(self, output_path):
        self.lockFile = os.path.join(output_path, "syncFile.lock")
        self.pid = os.getpid()
        self.id = None
        self.lockInfo = {}
        self.status = self.INIT
        self.createLockFile()

    def __len__(self):
        # define the size of the ProcessesManager object as the number of
        # processes
        return len(self.lockInfo)

    def createLockFile(self):
        """
            Create the lock file and write the information for the current
            process
        """
        with open(self.lockFile, "w") as fw:
            # write something so that the file is created, it will be later
            # overwritten
            fw.write("0\n")
        file_lock = open(self.lockFile, "r+")
        while True:
            # loop until a lock can be aqcuired
            try:
                # get lock
                fcntl.lockf(file_lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
                break
            except (IOError, OSError):
                time.sleep(2)
        self.lockInfo = self.getLockInfo(file_lock)
        if len(self.lockInfo):
            self.id = len(self.lockInfo)
        else:
            self.id = 0
        self.lockInfo[self.pid] = (self.id, self.status)
        self.writeLockInfo(file_lock)
        fcntl.lockf(file_lock, fcntl.LOCK_UN)
        file_lock.close()

    def getLockInfo(self, file_descriptor):
        """
            Return the info stored in the lock file

            :param file_descriptor: File object of the lock file
            :type file_descriptor: file

            :returns: dict -- A dictonary containing the information of the
{'fraction_non_alphanumeric': 0.0804079696394687, 'fraction_numerical': 0.0014231499051233396, 'mean_word_length': 1.8570460704607046, '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': '3819748', 'n_tokens_mistral': 1224, 'n_tokens_neox': 1182, 'n_words': 354}