Viewing File: /opt/alt/python38/lib/python3.8/site-packages/lockfile/__pycache__/__init__.cpython-38.pyc
U
UV$
@ s d Z ddlmZ ddlZddlZddlZddlZddlZeedsJej e_
eejdsbejjej_
dddd d
ddd
dddddg
ZG dd deZG dd deZG dd deZG dd d eZG dd
d
eZG dd deZG dd deZG dd
d
eZG dd deZG dd deZdd Zd d Zd!d Zd"d Zd(d#dZeed$rjd%d&l m!Z" e"j#Z$nd%d'l m%Z& e&j'Z$e$Z(dS ))a
lockfile.py - Platform-independent advisory file locks.
Requires Python 2.5 unless you apply 2.4.diff
Locking is done on a per-thread basis instead of a per-process basis.
Usage:
>>> lock = LockFile('somefile')
>>> try:
... lock.acquire()
... except AlreadyLocked:
... print 'somefile', 'is locked already.'
... except LockFailed:
... print 'somefile', 'can\'t be locked.'
... else:
... print 'got lock'
got lock
>>> print lock.is_locked()
True
>>> lock.release()
>>> lock = LockFile('somefile')
>>> print lock.is_locked()
False
>>> with lock:
... print lock.is_locked()
True
>>> print lock.is_locked()
False
>>> lock = LockFile('somefile')
>>> # It is okay to lock twice from the same thread...
>>> with lock:
... lock.acquire()
...
>>> # Though no counter is kept, so you can't unlock multiple times...
>>> print lock.is_locked()
False
Exceptions:
Error - base class for other exceptions
LockError - base class for all locking exceptions
AlreadyLocked - Another thread or process already holds the lock
LockFailed - Lock failed for some other reason
UnlockError - base class for all unlocking exceptions
AlreadyUnlocked - File was not locked.
NotMyLock - File was locked but not by the current thread/process
)absolute_importNcurrent_threadget_nameError LockErrorLockTimeout
AlreadyLocked
LockFailedUnlockError NotLocked NotMyLockLinkFileLock
MkdirFileLockSQLiteFileLockLockBaselockedc @ s e Zd ZdZdS )r zw
Base class for other exceptions.
>>> try:
... raise Error
... except Exception:
... pass
N__name__
__module____qualname____doc__ r r /__init__.pyr J s c @ s e Zd ZdZdS )r z
Base class for error arising from attempts to acquire the lock.
>>> try:
... raise LockError
... except Error:
... pass
Nr r r r r r V s c @ s e Zd ZdZdS )r zRaised when lock creation fails within a user-defined period of time.
>>> try:
... raise LockTimeout
... except LockError:
... pass
Nr r r r r r b s c @ s e Zd ZdZdS )r zSome other thread/process is locking the file.
>>> try:
... raise AlreadyLocked
... except LockError:
... pass
Nr r r r r r m s c @ s e Zd ZdZdS )r zLock file creation failed for some other reason.
>>> try:
... raise LockFailed
... except LockError:
... pass
Nr r r r r r x s c @ s e Zd ZdZdS )r
z
Base class for errors arising from attempts to release the lock.
>>> try:
... raise UnlockError
... except Error:
... pass
Nr r r r r r
s c @ s e Zd ZdZdS )r zRaised when an attempt is made to unlock an unlocked file.
>>> try:
... raise NotLocked
... except UnlockError:
... pass
Nr r r r r r s c @ s e Zd ZdZdS )r zRaised when an attempt is made to unlock a file someone else locked.
>>> try:
... raise NotMyLock
... except UnlockError:
... pass
Nr r r r r r s c @ s>