Try to acquire the lock.

        :Parameters:
            #. verbose (bool): Whether to be verbose about errors when encountered
            #. raiseError (bool): Whether to raise error exception when encountered

        :Returns:
            #. result (boolean): Whether the lock is succesfully acquired.
            #. code (integer, Exception): Integer code indicating the reason how the
               lock was successfully set or unsuccessfully acquired. When setting the
               lock generates an error, this will be caught and returned in a message
               Exception code.

               *  0: Lock is successfully set for normal reasons, In this case result
                  is True.
               *  1: Lock was already set, no need to set it again. In this case result
                  is True.
               *  2: Old and forgotten lock is found and removed. New lock is
                  successfully set, In this case result is True.
               *  3: Lock was not successfully set before timeout. In this case result
                  is False.
               *  Exception: Lock was not successfully set because of an unexpected error.
                  The error is caught and returned in this Exception. In this case
                  result is False.

def acquire_lock(self, verbose=VERBOSE, raiseError=RAISE_ERROR):
        """
        Try to acquire the lock.

        :Parameters:
            #. verbose (bool): Whether to be verbose about errors when encountered
            #. raiseError (bool): Whether to raise error exception when encountered

        :Returns:
            #. result (boolean): Whether the lock is succesfully acquired.
            #. code (integer, Exception): Integer code indicating the reason how the
               lock was successfully set or unsuccessfully acquired. When setting the
               lock generates an error, this will be caught and returned in a message
               Exception code.

               *  0: Lock is successfully set for normal reasons, In this case result
                  is True.
               *  1: Lock was already set, no need to set it again. In this case result
                  is True.
               *  2: Old and forgotten lock is found and removed. New lock is
                  successfully set, In this case result is True.
               *  3: Lock was not successfully set before timeout. In this case result
                  is False.
               *  Exception: Lock was not successfully set because of an unexpected error.
                  The error is caught and returned in this Exception. In this case
                  result is False.
        """
        #### ON WINDOWS MUST LOOK INTO THAT IN ORDER TO GET RID OF os.rename
        #### http://code.activestate.com/recipes/577794-win32-named-mutex-class-for-system-wide-mutex/
        # set acquire flag
        code         = 0
        acquired     = False
        t0 = t1      = time.time()
        LP           = self.__lockPass+'\n'
        bytesLP      = LP.encode()
        _lockingText = LP+'%.6f'+('\n%s'%self.__pid)
        _timeout     = self.__timeout
        # set general while loop with timeout condition
        while (t1-t0)<=_timeout:
            # try to set acquired to True by reading an empty lock file
            try:
                while not acquired and (t1-t0)<=_timeout:
                    if os.path.isfile(self.__lockPath):
                        try:
                            with open(self.__lockPath, 'rb') as fd:
                                lock = fd.readlines()
                        except:
                            # for the few time when lockPath got deleted or not available for reading
                            pass
                        else:
                            # lock file is empty or wrong
                            if len(lock) != 3:
                                code     = 0
                                acquired = True
                                break
                            if lock[0] == bytesLP:
                                code     = 1
                                acquired = True
                                break
                            if t1-float(lock[1]) > self.__deadLock: # check dead lock
                                acquired = True
                                code     = 2
                                break
                            if not pid_exists(int(lock[2])): # check for dead process which means lock is dead
                                acquired = True
                                code     = 2
                                break
                        # wait a bit
                        if self.__wait:
                            time.sleep(self.__wait)
                        t1 = time.time()
                    else:
                        acquired = True
                        break
            except Exception as err:
                code     = Exception( "Failed to check the lock (%s)"%(str(err),) )
                acquired = False
                if verbose: print(str(code))
                if raiseError: raise code
            # impossible to acquire because of an error or timeout.
            if not acquired:
                break
            # try to write lock
            try:
                tic = time.time()
                tmpFile = self.__lockPath
                # this is how to avoid multiple file writing os lock
                # must be tried on nt (windows) and tested for solution
                # os.rename on nt will crash if destination exists.
                if os.name=='posix':
                    tmpFile = '%s_%s'%(self.__lockPath,self.__uniqueID)
                with open(tmpFile, 'wb') as fd:
                    fd.write( str(_lockingText%t1).encode() )
                    fd.flush()
                    os.fsync(fd.fileno())
                if os.name=='posix':
                    os.rename(tmpFile,self.__lockPath)
                toc = time.time()
                if toc-tic >1:
                    print("PID '%s' writing '%s' is delayed by os for %s seconds. Lock timeout adjusted. MUST FIND A WAY TO FIX THAT"%(self.__pid,self.__lockPath,str(toc-tic)))
                    _timeout += toc-tic
            except Exception as err:
                code     = Exception("Failed to write the lock (%s)"%(str(err),) )
                acquired = False
                if verbose: print(str(code))
                if raiseError: raise code
                break
            # sleep for double tic-toc or 0.1 ms which ever one is bigger
            s = max([(toc-tic), 0.0001])
            time.sleep(s)
            # check if lock is still acquired by the same lock pass
            try:
                with open(self.__lockPath, 'rb') as fd:
                    lock = fd.readlines()
            except:
                lock = []
            if len(lock) >= 1:
                if lock[0] == bytesLP:
                    acquired = True
                    break
                else:
                    acquired = False
                    t1  = time.time()
                    continue
            else:
                acquired = False
                t1 = time.time()
                continue
        # return whether it is acquired or not
        if not acquired and not code:
            code = 3
        return acquired, code