Python portalocker.unlock() Examples

The following are 17 code examples of portalocker.unlock(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module portalocker , or try the search function .
Example #1
Source File: portalocker.py    From termite-visualizations with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def unlock(file):
        fcntl.flock(file.fileno(), fcntl.LOCK_UN) 
Example #2
Source File: portalocker.py    From zstack-utility with Apache License 2.0 5 votes vote down vote up
def unlock(file):
        fcntl.flock(file.fileno(), fcntl.LOCK_UN) 
Example #3
Source File: portalocker.py    From zstack-utility with Apache License 2.0 5 votes vote down vote up
def unlock(file):
        hfile = win32file._get_osfhandle(file.fileno())
        try:
            win32file.UnlockFileEx(hfile, 0, -0x10000, __overlapped)
        except pywintypes.error, exc_value:
            if exc_value[0] == 158:
                # error: (158, 'UnlockFileEx', 'The segment is already unlocked.')
                # To match the 'posix' implementation, silently ignore this error
                pass
            else:
                # Q:  Are there exceptions/codes we should be dealing with here?
                raise 
Example #4
Source File: newcron.py    From termite-visualizations with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def release(self):
        """
        this function writes into cron.master the time when cron job
        was completed
        """
        if not self.master.closed:
            portalocker.lock(self.master, portalocker.LOCK_EX)
            logger.debug('WEB2PY CRON: Releasing cron lock')
            self.master.seek(0)
            (start, stop) = cPickle.load(self.master)
            if start == self.now:  # if this is my lock
                self.master.seek(0)
                cPickle.dump((self.now, time.time()), self.master)
            portalocker.unlock(self.master)
            self.master.close() 
Example #5
Source File: cache.py    From termite-visualizations with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _open_shelve_and_lock(self):
        """Open and return a shelf object, obtaining an exclusive lock
        on self.locker first. Replaces the close method of the
        returned shelf instance with one that releases the lock upon
        closing."""

        storage = None
        locker = None
        locked = False
        try:
            locker = locker = open(self.locker_name, 'a')
            portalocker.lock(locker, portalocker.LOCK_EX)
            locked = True
            try:
                storage = shelve.open(self.shelve_name)
            except:
                logger.error('corrupted cache file %s, will try rebuild it'
                             % self.shelve_name)
                storage = None
            if storage is None:
                if os.path.exists(self.shelve_name):
                    os.unlink(self.shelve_name)
                storage = shelve.open(self.shelve_name)
            if not CacheAbstract.cache_stats_name in storage.keys():
                storage[CacheAbstract.cache_stats_name] = {
                    'hit_total': 0, 'misses': 0}
            storage.sync()
        except Exception, e:
            if storage:
                storage.close()
                storage = None
            if locked:
                portalocker.unlock(locker)
                locker.close()
            locked = False
            raise RuntimeError(
                'unable to create/re-create cache file %s' % self.shelve_name) 
Example #6
Source File: globals.py    From termite-visualizations with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _unlock(self, response):
        if response and response.session_file and response.session_locked:
            try:
                portalocker.unlock(response.session_file)
                response.session_locked = False
            except:  # this should never happen but happens in Windows
                pass 
Example #7
Source File: portalocker.py    From termite-visualizations with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def close(self):
        if not self.file is None:
            unlock(self.file)
            self.file.close()
            self.file = None 
Example #8
Source File: portalocker.py    From termite-visualizations with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def unlock(file):
        pass 
Example #9
Source File: __init__.py    From concurrent-log-handler with Apache License 2.0 5 votes vote down vote up
def _do_unlock(self):
        if self.stream_lock:
            if self.is_locked:
                unlock(self.stream_lock)
                self.is_locked = False
            self.stream_lock.close()
            self.stream_lock = None
        else:
            self._console_log("No self.stream_lock to unlock", stack=True) 
Example #10
Source File: portalocker.py    From termite-visualizations with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def unlock(file):
        hfile = win32file._get_osfhandle(file.fileno())
        win32file.UnlockFileEx(hfile, 0, 0x7fff0000, __overlapped) 
Example #11
Source File: portalocker.py    From pydal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def close(self):
        if self.file is not None:
            unlock(self.file)
            self.file.close()
            self.file = None 
Example #12
Source File: portalocker.py    From pydal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def unlock(file):
        pass 
Example #13
Source File: portalocker.py    From pydal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def unlock(file):
        fcntl.flock(file.fileno(), fcntl.LOCK_UN) 
Example #14
Source File: portalocker.py    From pydal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def unlock(file):
        hfile = msvcrt.get_osfhandle(file.fileno())
        overlapped = OVERLAPPED()
        UnlockFileEx(hfile, 0, 0, 0xFFFF0000, ctypes.byref(overlapped)) 
Example #15
Source File: portalocker.py    From edwin with Apache License 2.0 5 votes vote down vote up
def unlock(file):
        fcntl.flock(_getfd(file), fcntl.LOCK_UN) 
Example #16
Source File: portalocker.py    From edwin with Apache License 2.0 5 votes vote down vote up
def unlock(file):
        hfile = win32file._get_osfhandle(_getfd(file))
        try:
            win32file.UnlockFileEx(hfile, 0, -0x10000, __overlapped)
        except pywintypes.error, exc_value:
            if exc_value[0] == 158:
                # error: (158, 'UnlockFileEx', 'The segment is already unlocked.')
                # To match the 'posix' implementation, silently ignore this error
                pass
            else:
                # Q:  Are there exceptions/codes we should be dealing with here?
                raise 
Example #17
Source File: newcron.py    From termite-visualizations with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def acquire(self, startup=False):
        """
        returns the time when the lock is acquired or
        None if cron already running

        lock is implemented by writing a pickle (start, stop) in cron.master
        start is time when cron job starts and stop is time when cron completed
        stop == 0 if job started but did not yet complete
        if a cron job started within less than 60 seconds, acquire returns None
        if a cron job started before 60 seconds and did not stop,
        a warning is issue "Stale cron.master detected"
        """
        if sys.platform == 'win32':
            locktime = 59.5
        else:
            locktime = 59.99
        if portalocker.LOCK_EX is None:
            logger.warning('WEB2PY CRON: Disabled because no file locking')
            return None
        self.master = open(self.path, 'rb+')
        try:
            ret = None
            portalocker.lock(self.master, portalocker.LOCK_EX)
            try:
                (start, stop) = cPickle.load(self.master)
            except:
                (start, stop) = (0, 1)
            if startup or self.now - start > locktime:
                ret = self.now
                if not stop:
                    # this happens if previous cron job longer than 1 minute
                    logger.warning('WEB2PY CRON: Stale cron.master detected')
                logger.debug('WEB2PY CRON: Acquiring lock')
                self.master.seek(0)
                cPickle.dump((self.now, 0), self.master)
                self.master.flush()
        finally:
            portalocker.unlock(self.master)
        if not ret:
            # do this so no need to release
            self.master.close()
        return ret