o
    ek/                     @   s   g d Z 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ZddlZddl	m
Z
mZ zddlZW n ey?   ddlZY nw ddlmZ ddlmZ ejjZddlmZmZmZmZmZ G dd	 d	eZe ZG d
d deZG dd deZdS ))QueueSimpleQueueJoinableQueue    N)EmptyFull   )
connection)context)debuginfoFinalizeregister_after_fork
is_exitingc                   @   s   e Zd Zd-ddZdd Zdd Zdd	 Zd.ddZd/ddZd/ddZ	dd Z
dd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zed%d& Zed'd( Zed)d* Zed+d, ZdS )0r   r   c                C   s   |dkr
ddl m} || _tjdd\| _| _| | _t	
 | _tjdkr*d | _n| | _||| _d| _|   tjdkrIt| tj d S d S )Nr   r   )SEM_VALUE_MAXFduplexwin32)Zsynchronizer   _maxsizer   Pipe_reader_writerLock_rlockosgetpid_opidsysplatform_wlockBoundedSemaphore_sem_ignore_epipe_resetr   r   _after_forkselfmaxsizectx r(   CD:\Projects\ConvertPro\env\Lib\site-packages\multiprocess/queues.py__init__(   s   




zQueue.__init__c                 C   s.   t |  | j| j| j| j| j| j| j| j	fS N)
r	   assert_spawningr!   r   r   r   r   r   r    r   r%   r(   r(   r)   __getstate__<   s   
zQueue.__getstate__c              	   C   s0   |\| _ | _| _| _| _| _| _| _|   d S r+   )	r!   r   r   r   r   r   r    r   r"   r%   stater(   r(   r)   __setstate__A   s   zQueue.__setstate__c                 C   s   t d | jdd d S )NzQueue._after_fork()T)
after_fork)r
   r"   r-   r(   r(   r)   r#   F   s   zQueue._after_forkFc                 C   sj   |r| j   ntt | _ t | _d | _d | _	d| _
d| _d | _| jj| _| jj| _| jj| _d S NF)	_notempty_at_fork_reinit	threading	Conditionr   collectionsdeque_buffer_thread_jointhread_joincancelled_closed_closer   
send_bytes_send_bytesr   
recv_bytes_recv_bytespoll_poll)r%   r2   r(   r(   r)   r"   J   s   


zQueue._resetTNc                 C   s|   | j rtd| d| j||st| j | jd u r!|   | j	| | j
  W d    d S 1 s7w   Y  d S NQueue 
 is closed)r>   
ValueErrorr    acquirer   r4   r;   _start_threadr:   appendnotifyr%   objblocktimeoutr(   r(   r)   putY   s   
"z	Queue.putc                 C   s   | j rtd| d|r.|d u r.| j |  }W d    n1 s#w   Y  | j  nF|r:ttdtj | }| j||sCt	z*|rX|ttdtj  }| 
|sWt	n| 
 s^t	|  }| j  W | j  n| j  w t|S )NrG   rH   	monotonic)r>   rI   r   rC   r    releasegetattrtimerJ   r   rE   _ForkingPicklerloads)r%   rP   rQ   resdeadliner(   r(   r)   gete   s.   


z	Queue.getc                 C   s   | j | jj  S r+   )r   r    _semlockZ
_get_valuer-   r(   r(   r)   qsize   s   zQueue.qsizec                 C   
   |    S r+   rE   r-   r(   r(   r)   empty      
zQueue.emptyc                 C   s   | j j S r+   )r    r\   _is_zeror-   r(   r(   r)   full      z
Queue.fullc                 C   s
   |  dS r3   )r[   r-   r(   r(   r)   
get_nowait   ra   zQueue.get_nowaitc                 C   s   |  |dS r3   )rR   r%   rO   r(   r(   r)   
put_nowait   rd   zQueue.put_nowaitc                 C   s$   d| _ | j}|rd | _|  d S d S )NT)r>   r?   )r%   closer(   r(   r)   rh      s   
zQueue.closec                 C   s2   t d | jsJ d| | jr|   d S d S )NzQueue.join_thread()zQueue {0!r} not closed)r
   r>   formatr<   r-   r(   r(   r)   join_thread   s
   zQueue.join_threadc                 C   s4   t d d| _z| j  W d S  ty   Y d S w )NzQueue.cancel_join_thread()T)r
   r=   r<   cancelAttributeErrorr-   r(   r(   r)   cancel_join_thread   s   zQueue.cancel_join_threadc                 C   s   t d | j  tjtj| j| j| j| j	| j
j| jj| j| j| jf	dd| _d| j_t d | j  t d | jsKt| jtjt| jgdd| _t| tj| j| jgd	d| _d S )
NzQueue._start_thread()ZQueueFeederThread)targetargsnameTzdoing self._thread.start()z... done self._thread.start())Zexitpriority
   )r
   r:   clearr6   Threadr   _feedr4   rA   r   r   rh   r   r!   _on_queue_feeder_errorr    r;   daemonstartr=   r   _finalize_joinweakrefrefr<   _finalize_closer?   r-   r(   r(   r)   rK      s4   


zQueue._start_threadc                 C   s6   t d |  }|d ur|  t d d S t d d S )Nzjoining queue threadz... queue thread joinedz... queue thread already dead)r
   join)Ztwrthreadr(   r(   r)   ry      s   zQueue._finalize_joinc                 C   sD   t d | | t |  W d    d S 1 sw   Y  d S )Nztelling queue thread to quit)r
   rL   	_sentinelrM   )buffernotemptyr(   r(   r)   r|      s
   

"zQueue._finalize_closec	              
   C   sf  t d |j}	|j}
|j}| j}t}tjdkr|j}|j}nd }	 zT|	  z
| s+|  W |
  n|
  w z6	 | }||u rKt d |  |  W W d S t	|}|d u rY|| n|  z	|| W |  n|  w q6 t
ys   Y nw W n< ty } z0|rt|ddtjkrW Y d }~d S t rtd| W Y d }~d S |  ||| W Y d }~nd }~ww q!)Nz$starting thread to feed data to piper   r   z%feeder thread got sentinel -- exitingerrnor   zerror in queue thread: %s)r
   rJ   rT   waitpopleftr   r   r   rW   dumps
IndexError	ExceptionrU   r   EPIPEr   r   )r   r   r@   Z	writelockZreader_closeZwriter_closeZignore_epipeonerrorZ	queue_semZnacquireZnreleaseZnwaitZbpopleftsentinelZwacquireZwreleaserO   er(   r(   r)   ru      sb   




zQueue._feedc                 C   s   ddl }|  dS )z
        Private API hook called when feeding data in the background thread
        raises an exception.  For overriding by concurrent.futures.
        r   N)	traceback	print_exc)r   rO   r   r(   r(   r)   rv     s   zQueue._on_queue_feeder_errorr   )FTN)__name__
__module____qualname__r*   r.   r1   r#   r"   rR   r[   r]   r`   rc   re   rg   rh   rj   rm   rK   staticmethodry   r|   ru   rv   r(   r(   r(   r)   r   &   s2    



!
	

>r   c                   @   s@   e Zd ZdddZdd Zdd Zdd
dZdd Zdd Zd	S )r   r   c                C   s*   t j| ||d |d| _| | _d S )N)r'   r   )r   r*   	Semaphore_unfinished_tasksr7   _condr$   r(   r(   r)   r*   +  s   zJoinableQueue.__init__c                 C   s   t | | j| jf S r+   )r   r.   r   r   r-   r(   r(   r)   r.   0  s   zJoinableQueue.__getstate__c                 C   s,   t | |d d  |dd  \| _| _d S )N)r   r1   r   r   r/   r(   r(   r)   r1   3  s   zJoinableQueue.__setstate__TNc              	   C   s   | j rtd| d| j||st| j= | j! | jd u r%|   | j	
| | j  | j  W d    n1 s?w   Y  W d    d S W d    d S 1 sWw   Y  d S rF   )r>   rI   r    rJ   r   r4   r   r;   rK   r:   rL   r   rT   rM   rN   r(   r(   r)   rR   7  s   

PzJoinableQueue.putc                 C   sf   | j & | jdstd| jj r!| j   W d    d S W d    d S 1 s,w   Y  d S )NFz!task_done() called too many times)r   r   rJ   rI   r\   rb   
notify_allr-   r(   r(   r)   	task_doneD  s   "zJoinableQueue.task_donec                 C   sR   | j  | jj s| j   W d    d S W d    d S 1 s"w   Y  d S r+   )r   r   r\   rb   r   r-   r(   r(   r)   r}   K  s   "zJoinableQueue.joinr   r   )	r   r   r   r*   r.   r1   rR   r   r}   r(   r(   r(   r)   r   )  s    

r   c                   @   sN   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	e
ejZdS )r   c                C   sJ   t jdd\| _| _| | _| jj| _tj	dkrd | _
d S | | _
d S )NFr   r   )r   r   r   r   r   r   rD   rE   r   r   r   )r%   r'   r(   r(   r)   r*   V  s   



zSimpleQueue.__init__c                 C   s   | j   | j  d S r+   )r   rh   r   r-   r(   r(   r)   rh   _  s   
zSimpleQueue.closec                 C   r^   r+   r_   r-   r(   r(   r)   r`   c  ra   zSimpleQueue.emptyc                 C   s   t |  | j| j| j| jfS r+   )r	   r,   r   r   r   r   r-   r(   r(   r)   r.   f  s   
zSimpleQueue.__getstate__c                 C   s"   |\| _ | _| _| _| j j| _d S r+   )r   r   r   r   rD   rE   r/   r(   r(   r)   r1   j  s   zSimpleQueue.__setstate__c                 C   s:   | j  | j }W d    n1 sw   Y  t|S r+   )r   r   rB   rW   rX   )r%   rY   r(   r(   r)   r[   n  s   
zSimpleQueue.getc                 C   s\   t |}| jd u r| j| d S | j | j| W d    d S 1 s'w   Y  d S r+   )rW   r   r   r   r@   rf   r(   r(   r)   rR   t  s   

"zSimpleQueue.putN)r   r   r   r*   rh   r`   r.   r1   r[   rR   classmethodtypesGenericAlias__class_getitem__r(   r(   r(   r)   r   T  s    	
r   ) __all__r   r   r6   r8   rV   r   rz   r   queuer   r   Z_multiprocess_multiprocessingImportError r   r	   Z	reductionZForkingPicklerrW   utilr
   r   r   r   r   objectr   r   r   r   r(   r(   r(   r)   <module>   s0   	 z
+