관리-도구
편집 파일: mkdirlockfile.cpython-36.opt-1.pyc
3 �Pf � @ sd d dl mZmZ d dlZd dlZd dlZd dlZddlmZm Z m Z mZmZm Z G dd� de�ZdS )� )�absolute_import�divisionN� )�LockBase� LockFailed� NotLocked� NotMyLock�LockTimeout� AlreadyLockedc @ sD e Zd ZdZddd�Zddd�Zdd � Zd d� Zdd � Zdd� Z dS )� MkdirLockFilez"Lock file by creating a directory.TNc C s6 t j| |||� tjj| jd| j| j| jf �| _ dS )zs >>> lock = MkdirLockFile('somefile') >>> lock = MkdirLockFile('somefile', threaded=False) z%s.%s%sN) r �__init__�os�path�join� lock_fileZhostnameZtname�pid�unique_name)�selfr Zthreaded�timeout� r �#/usr/lib/python3.6/mkdirlockfile.pyr s zMkdirLockFile.__init__c C s |d k r|n| j }tj� }|d k r2|dkr2||7 }|d kr@d}ntd|d �}x�ytj| j� W n� tk r� tj� d }|j t j kr�tjj| j �r�d S |d k r�tj� |kr�|dkr�td| j ��ntd| j ��tj|� ntd| j ��Y qPX t| j d�j� d S qPW d S ) Nr g�������?� r z&Timeout waiting to acquire lock for %sz%s is already lockedzfailed to create %s�wb)r �time�maxr �mkdirr �OSError�sys�exc_info�errnoZEEXISTr �existsr r r Zsleepr �open�close)r r Zend_time�wait�errr r r �acquire s2 zMkdirLockFile.acquirec C sP | j � std| j ��ntjj| j�s4td| j ��tj| j� tj| j � d S )Nz%s is not lockedz%s is locked, but not by me) � is_lockedr r r r r r �unlink�rmdirr )r r r r �releaseA s zMkdirLockFile.releasec C s t jj| j�S )N)r r r r )r r r r r&