a
    5ghk/                     @   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0 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d0d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 )1r   r   c                C   s   |dkrddl m} || _tjdd\| _| _| | _t	
 | _tjdkrTd | _n
| | _||| _d| _|   tjdkrt| tj d S )Nr   r   )SEM_VALUE_MAXFZ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'   c/mounts/lovelace/software/anaconda3/envs/metaDMG/lib/python3.9/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$   r1   r'   r'   r(   r!   J   s    


zQueue._resetTNc                 C   sz   | j rtd| d| j||s(t| j8 | jd u rB|   | j	| | j
  W d    n1 sl0    Y  d S NQueue 
 is closed)r=   
ValueErrorr   acquirer   r3   r:   _start_threadr9   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 sF0    Y  | j  n|rtttdtj | }| j||st	zT|r|ttdtj  }| 
|st	n| 
 st	|  }| j  W | j  n| j  0 t|S )NrF   rG   	monotonic)r=   rH   r   rB   r   releasegetattrtimerI   r   rD   _ForkingPicklerloads)r$   rO   rP   resdeadliner'   r'   r(   gete   s*    &
z	Queue.getc                 C   s   | j | jj  S r*   )r   r   _semlock
_get_valuer,   r'   r'   r(   qsize   s    zQueue.qsizec                 C   s
   |    S r*   rD   r,   r'   r'   r(   empty   s    zQueue.emptyc                 C   s   | j j S r*   )r   r[   _is_zeror,   r'   r'   r(   full   s    z
Queue.fullc                 C   s
   |  dS r2   )rZ   r,   r'   r'   r(   
get_nowait   s    zQueue.get_nowaitc                 C   s   |  |dS r2   )rQ   r$   rN   r'   r'   r(   
put_nowait   s    zQueue.put_nowaitc                 C   s    d| _ | j}|rd | _|  d S )NT)r=   r>   )r$   closer'   r'   r(   re      s
    zQueue.closec                 C   s.   t d | jsJ d| | jr*|   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 n ty.   Y n0 d S )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st| 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
   r9   clearr5   Threadr   _feedr3   r@   r   r   re   r   r    _on_queue_feeder_errorr   r:   daemonstartr<   r   _finalize_joinweakrefrefr;   _finalize_closer>   r,   r'   r'   r(   rJ      s4    


zQueue._start_threadc                 C   s4   t d |  }|d ur(|  t d nt d d S )Nzjoining queue threadz... queue thread joinedz... queue thread already dead)r
   join)Ztwrthreadr'   r'   r(   rv      s    
zQueue._finalize_joinc                 C   sB   t d |" | t |  W d    n1 s40    Y  d S )Nztelling queue thread to quit)r
   rK   	_sentinelrL   )buffernotemptyr'   r'   r(   ry      s    
zQueue._finalize_closec	              
   C   sr  t d |j}	|j}
|j}| j}t}tjdkr<|j}|j}nd }z|	  z| sT|  W |
  n|
  0 zn| }||u rt d |  |  W W d S t	|}|d u r|| qh|  z|| W |  qh|  0 qhW n t
y   Y n0 W q@ tyj } zf|r$t|ddtjkr$W Y d }~d S t rDtd| W Y d }~d S |  ||| W Y d }~q@d }~0 0 q@d S )Nz$starting thread to feed data to piper   z%feeder thread got sentinel -- exitingerrnor   zerror in queue thread: %s)r
   rI   rS   waitpopleftr|   r   r   rV   dumps
IndexError	ExceptionrT   r   EPIPEr   r   )r}   r~   r?   Z	writelockZreader_closeZwriter_closeZignore_epipeonerrorZ	queue_semZnacquireZnreleaseZnwaitZbpopleftsentinelZwacquireZwreleaserN   er'   r'   r(   rr      sP    





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   rN   r   r'   r'   r(   rs     s    zQueue._on_queue_feeder_error)r   )F)TN)TN)__name__
__module____qualname__r)   r-   r0   r"   r!   rQ   rZ   r]   r_   ra   rb   rd   re   rg   rj   rJ   staticmethodrv   ry   rr   rs   r'   r'   r'   r(   r   &   s0   



!
	

>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_tasksr6   _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   r0   r   r   r.   r'   r'   r(   r0   3  s    zJoinableQueue.__setstate__TNc              	   C   s   | j rtd| d| j||s(t| jh | jB | jd u rJ|   | j	
| | j  | j  W d    n1 s~0    Y  W d    n1 s0    Y  d S rE   )r=   rH   r   rI   r   r3   r   r:   rJ   r9   rK   r   rS   rL   rM   r'   r'   r(   rQ   7  s    

zJoinableQueue.putc                 C   sT   | j : | jdstd| jj r2| j   W d    n1 sF0    Y  d S )NFz!task_done() called too many times)r   r   rI   rH   r[   r`   
notify_allr,   r'   r'   r(   	task_doneD  s
    zJoinableQueue.task_donec                 C   s@   | j & | jj s| j   W d    n1 s20    Y  d S r*   )r   r   r[   r`   r   r,   r'   r'   r(   rz   K  s    zJoinableQueue.join)r   )TN)	r   r   r   r)   r-   r0   rQ   r   rz   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   sH   t jdd\| _| _| | _| jj| _tj	dkr:d | _
n
| | _
d S )NFr   r   )r   r   r   r   r   r   rC   rD   r   r   r   )r$   r&   r'   r'   r(   r)   V  s    


zSimpleQueue.__init__c                 C   s   | j   | j  d S r*   )r   re   r   r,   r'   r'   r(   re   _  s    
zSimpleQueue.closec                 C   s
   |    S r*   r^   r,   r'   r'   r(   r_   c  s    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   rC   rD   r.   r'   r'   r(   r0   j  s    zSimpleQueue.__setstate__c                 C   s:   | j  | j }W d    n1 s&0    Y  t|S r*   )r   r   rA   rV   rW   )r$   rX   r'   r'   r(   rZ   n  s    (zSimpleQueue.getc                 C   sX   t |}| jd u r"| j| n2| j | j| W d    n1 sJ0    Y  d S r*   )rV   r   r   r   r?   rc   r'   r'   r(   rQ   t  s
    

zSimpleQueue.putN)r   r   r   r)   re   r_   r-   r0   rZ   rQ   classmethodtypesGenericAlias__class_getitem__r'   r'   r'   r(   r   T  s   	
r   ) __all__r   r   r5   r7   rU   r   rw   r   queuer   r   Z_multiprocess_multiprocessingImportError r   r	   Z	reductionZForkingPicklerrV   utilr
   r   r   r   r   objectr   r|   r   r   r'   r'   r'   r(   <module>
   s,    z
+