관리-도구
편집 파일: semaphore_tracker.cpython-34.pyo
� e f� � @ s� d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l m Z d d l m Z d d d g Z Gd d � d e � Z e � Z e j Z e j Z e j Z e j Z d d � Z d S)� N� )�spawn)�util�ensure_running�register� unregisterc @ sX e Z d Z d d � Z d d � Z d d � Z d d � Z d d � Z d d � Z d S)�SemaphoreTrackerc C s t j � | _ d | _ d S)N)� threadingZLock�_lock�_fd)�self� r �F/opt/alt/python34/lib64/python3.4/multiprocessing/semaphore_tracker.py�__init__ s zSemaphoreTracker.__init__c C s | j � | j S)N)r r )r r r r �getfd! s zSemaphoreTracker.getfdc C s | j �� | j d k r d Sg } y | j t j j � � Wn t k rQ Yn Xd } t j � \ } } z yW | j | � t j � } | g t j � } | d | | g 7} t j | | | � Wn t j | � � Yn X| | _ Wd t j | � XWd QXd S)z�Make sure that semaphore tracker process is running. This can be run from any process. Usually a child process will use the semaphore created by its parent.Nz;from multiprocessing.semaphore_tracker import main;main(%d)z-c)r r �append�sys�stderr�fileno� Exception�os�piper Zget_executabler Z_args_from_interpreter_flagsZspawnv_passfds�close)r Zfds_to_pass�cmd�r�wZexe�argsr r r r % s* zSemaphoreTracker.ensure_runningc C s | j d | � d S)z2Register name of semaphore with semaphore tracker.ZREGISTERN)�_send)r �namer r r r C s zSemaphoreTracker.registerc C s | j d | � d S)z4Unregister name of semaphore with semaphore tracker.Z UNREGISTERN)r )r r r r r r G s zSemaphoreTracker.unregisterc C s_ | j � d j | | � j d � } t | � d k rF t d � � n t j | j | � } d S)Nz{0}:{1} �asciii z name too long)r �format�encode�len� ValueErrorr �writer )r r r �msg�nbytesr r r r K s zSemaphoreTracker._sendN) �__name__� __module__�__qualname__r r r r r r r r r r r s r c , C s� t j t j t j � t j t j t j � x= t j t j f D]) } y | j � Wq? t k rg Yq? Xq? Wt � } z� t | d � �� } x� | D]� } yg | j � j d � \ } } | d k r� | j | � n, | d k r� | j | � n t d | � � Wq� t k r4y t j t j � � Wn Yn XYq� Xq� WWd QXWd | r|y t j d t | � � Wq|t k rxYq|Xn xu | D]m } zc | j d � } y t j | � Wn<