U
    .Wjÿ  ã                   @   sÆ   d Z ddlmZ G dd„ dƒZdd„ Zde_dd	„ Zd
d„ Zdd„ Zdd„ Z	ddd„Z
eƒ Zdd„ Zdd„ Zdd„ ZdadadadazddlZW n ek
r¨   dZY nX eZe
dƒ ddddgZdS )zT
A module to provide some very basic threading primitives, such as
synchronization.
é    ©Úwrapsc                   @   s   e Zd ZdZdd„ ZdS )Ú	DummyLockzF
    Hack to allow locks to be unpickled on an unthreaded system.
    c                 C   s   t dfS ©N© ©Úunpickle_lock©Úselfr   r   údc:\users\psant\downloads\hotstarbackend\school\venv38\Lib\site-packages\twisted/python/threadable.pyÚ
__reduce__   s    zDummyLock.__reduce__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      s   r   c                   C   s   t d k	rtƒ S tƒ S d S ©N)ÚthreadingmoduleÚXLockr   r   r   r   r   r      s    r   Tc                 C   s>   d| j kr0t ¡  d| j kr(tƒ | j d< t ¡  | j ¡  d S )NÚ_threadable_lock)Ú__dict__Ú_synchLockCreatorÚacquirer   Úreleaser   r	   r   r   r   Ú	_synchPre!   s    

r   c                 C   s   | j  ¡  d S r   )r   r   r	   r   r   r   Ú
_synchPost*   s    r   c                    s   t ˆ ƒ‡ fdd„ƒ}|S )Nc                    s,   t | ƒ zˆ | f|ž|ŽW ¢S t| ƒ X d S r   )r   r   )r
   ÚargsÚkwargs©Úfunctionr   r   Úsync/   s    z_sync.<locals>.syncr   )Úklassr   r   r   r   r   Ú_sync.   s    r!   c                  G   s>   t dk	r:| D ],}|jD ] }t||j| ƒ}t|||ƒ qqdS )a&  
    Make all methods listed in each class' synchronized attribute synchronized.

    The synchronized attribute should be a list of strings, consisting of the
    names of methods that must be synchronized. If we are running in threaded
    mode these methods will be wrapped with a lock.
    N)r   Zsynchronizedr!   r   Úsetattr)Zklassesr    Ú
methodNamer   r   r   r   Úsynchronize:   s
    
r$   é   c                 C   sJ   | r8t sFtdk	r.da G dd„ dtjƒatƒ aqFtdƒ‚nt rFtdƒ‚n dS )zbInitialize threading.

    Don't bother calling this.  If it needs to happen, it will happen.
    NTc                   @   s   e Zd Zdd„ ZdS )r   c                 S   s   t dfS r   r   r	   r   r   r   r   V   s    zXLock.__reduce__N)r   r   r   r   r   r   r   r   r   U   s   r   z:Cannot initialize threading, platform lacks thread supportzCannot uninitialize threads)Úthreadedr   Ú_RLockr   r   ÚRuntimeError)Zwith_threadsr   r   r   ÚinitI   s    ÿ
r)   c                   C   s   t d krtS t  ¡ jS r   )r   Ú_dummyIDÚcurrent_threadÚidentr   r   r   r   ÚgetThreadIDh   s    r-   c                   C   s
   t tƒ kS )zCAre we in the thread responsible for I/O requests (the event loop)?)ÚioThreadr-   r   r   r   r   ÚisInIOThreadn   s    r/   c                   C   s
   t ƒ adS )z8Mark the current thread as responsible for I/O requests.N)r-   r.   r   r   r   r   ÚregisterAsIOThreads   s    r0   NFr   )r%   )r   Ú	functoolsr   r   r   Z__safe_for_unpickling__r   r   r!   r$   r)   Úobjectr*   r-   r/   r0   r.   r&   r   r   Ú	threadingZ_threadingmoduleÚImportErrorr   Ú__all__r   r   r   r   Ú<module>   s0   		

