Ticket #9133: lockexception.diff

File lockexception.diff, 1.0 KB (added by magneto, 16 years ago)

Lock Exception

  • django/core/files/locks.py

     
    4040except (ImportError, AttributeError):
    4141    pass
    4242
     43class LockException(Exception):
     44    # Error codes:
     45    LOCK_FAILED = 1
     46
    4347def fd(f):
    4448    """Get a filedescriptor from something which could be a file or an fd."""
    4549    return hasattr(f, 'fileno') and f.fileno() or f
     
    5458        win32file.UnlockFileEx(hfile, 0, -0x10000, __overlapped)
    5559elif system_type == 'posix':
    5660    def lock(file, flags):
    57         fcntl.lockf(fd(file), flags)
     61        try:
     62            fcntl.lockf(fd(file), flags)
     63        except IOError, exc_value:
     64            #  IOError: [Errno 11] Resource temporarily unavailable
     65            if exc_value[0] == 11:
     66                raise LockException(LockException.LOCK_FAILED, exc_value[1])
     67            else:
     68                raise
    5869
    5970    def unlock(file):
    6071        fcntl.lockf(fd(file), fcntl.LOCK_UN)
Back to Top