3 Pf\ @sPddlmZddlZddlZddlmZmZmZmZm Z m Z GdddeZ dS))absolute_importN)LockBase LockFailed NotLocked NotMyLock LockTimeout AlreadyLockedc@s:eZdZdZd ddZddZddZd d Zd d ZdS) LinkLockFilezLock access to a file using atomic property of link(2). >>> lock = LinkLockFile('somefile') >>> lock = LinkLockFile('somefile', threaded=False) NcCs"yt|jdjWn"tk r6td|jYnX|dk rD|n|j}tj}|dk rj|dkrj||7}xytj|j|j Wnt k rtj |jj }|dkrdS|dk rtj|krtj |j|dkrtd|jntd|jtj|dk r |dp dYqlXdSqlWdS) Nwbzfailed to create %srz&Timeout waiting to acquire lock for %sz%s is already locked g?)open unique_namecloseIOErrorrtimeouttimeoslink lock_fileOSErrorstatst_nlinkunlinkrpathr Zsleep)selfrZend_timeZnlinksr"/usr/lib/python3.6/linklockfile.pyacquires0   $zLinkLockFile.acquirecCsP|jstd|jntjj|js4td|jtj|jtj|jdS)Nz%s is not lockedz%s is locked, but not by me) is_lockedrrrexistsrrrr)rrrrrelease7s  zLinkLockFile.releasecCstjj|jS)N)rrr!r)rrrrr ?szLinkLockFile.is_lockedcCs(|jo&tjj|jo&tj|jjdkS)Nr )r rrr!rrr)rrrr i_am_lockingBszLinkLockFile.i_am_lockingcCstjj|jrtj|jdS)N)rrr!rr)rrrr break_lockGszLinkLockFile.break_lock)N) __name__ __module__ __qualname____doc__rr"r r#r$rrrrr s  &r ) Z __future__rrrrrrrrr r rrrrs