a
�RLg�.�@s�gd�ZddlZddlZddlZddlZddlZddlZddlZddlZddl m
Z
mZddlZddl
mZddl
mZejjZddlmZmZmZmZmZGdd �d e�Ze�ZGd
d�de�ZGdd
�d
e�ZdS))�Queue�SimpleQueue�
JoinableQueue�N)�Empty�Full�)�
connection)�context)�debug�info�Finalize�register_after_fork�
is_exitingc@s�eZdZd-dd�Zdd�Zdd�Zdd �Zd.dd�Zd/dd�Zd0dd�Z dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd �Zd!d"�Zd#d$�Zed%d&��Zed'd(��Zed)d*��Zed+d,��ZdS)1rrcCs�|dkrddlm}||_tjdd�\|_|_|��|_t �
�|_tj
dkrTd|_n
|��|_|�|�|_d|_|��tj
dkr�t|tj�dS)Nrr)�
SEM_VALUE_MAXF�Zduplex�win32)Zsynchronizer�_maxsizer�Pipe�_reader�_writer�Lock�_rlock�os�getpid�_opid�sys�platform�_wlockZBoundedSemaphore�_sem�
_ignore_epipe�_resetr
r�_after_fork��self�maxsize�ctx�r&�,/usr/lib/python3.9/multiprocessing/queues.py�__init__%s
zQueue.__init__cCs.t�|�|j|j|j|j|j|j|j|j fS�N)
r �assert_spawningrrrrrrrr�r#r&r&r'�__getstate__9s
�zQueue.__getstate__c Cs0|\|_|_|_|_|_|_|_|_|��dSr)) rrrrrrrrr �r#�stater&r&r'�__setstate__>s�zQueue.__setstate__cCstd�|jdd�dS)NzQueue._after_fork()T)�
after_fork)r
r r+r&r&r'r!CszQueue._after_forkFcCsj|r|j��nt�t���|_t��|_d|_d|_ d|_
d|_d|_|j
j|_|jj|_|jj|_dS�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#r0r&r&r'r Gs
zQueue._resetTNcCsz|jrtd|�d���|j�||�s(t�|j�8|jdurB|��|j� |�|j�
�Wd�n1sl0YdS�NzQueue z
is closed)r<�
ValueErrorr�acquirerr2r9�
_start_threadr8�append�notify�r#�obj�block�timeoutr&r&r'�putVs
z Queue.putcCs�|jrtd|�d���|r\|dur\|j�|��}Wd�n1sF0Y|j��n||rlt��|}|j�||�s~t �zL|r�|t��}|�
|�s�t �n|�
�s�t �|��}|j��W|j��n|j��0t�|�SrD)
r<rErrAr�release�time� monotonicrFrrC�_ForkingPickler�loads)r#rLrM�resZdeadliner&r&r'�getbs*&
z Queue.getcCs|j|jj��Sr))rr�_semlockZ
_get_valuer+r&r&r'�qsize|szQueue.qsizecCs
|��Sr)�rCr+r&r&r'�empty�szQueue.emptycCs|jj��Sr))rrV�_is_zeror+r&r&r'�full�sz
Queue.fullcCs
|�d�Sr1)rUr+r&r&r'�
get_nowait�szQueue.get_nowaitcCs|�|d�Sr1)rN�r#rKr&r&r'�
put_nowait�szQueue.put_nowaitcCsHd|_z$|j��W|j}|rDd|_|�n|j}|rBd|_|�0dS)NT)r<r�closer=)r#r_r&r&r'r_�s�zQueue.closecCs.td�|jsJd�|���|jr*|��dS)NzQueue.join_thread()zQueue {0!r} not closed)r
r<�formatr:r+r&r&r'�join_thread�szQueue.join_threadcCs4td�d|_z|j��Wnty.Yn0dS)NzQueue.cancel_join_thread()T)r
r;r:Zcancel�AttributeErrorr+r&r&r'�cancel_join_thread�szQueue.cancel_join_threadc
Cs�td�|j��tjtj|j|j|j|j |j
j|j|j
|jfdd�|_d|j_td�|j��td�|js�t|jtjt�|j�gdd�|_t|tj|j|jgd d�|_dS)
NzQueue._start_thread()ZQueueFeederThread)�target�args�nameTzdoing self._thread.start()z... done self._thread.start()���)Zexitpriority�
)r
r8�clearr4ZThreadr�_feedr2r?rrr_r�_on_queue_feeder_errorrr9Zdaemon�startr;r�_finalize_join�weakref�refr:�_finalize_closer=r+r&r&r'rG�s2
��
�
�zQueue._start_threadcCs4td�|�}|dur(|��td�ntd�dS)Nzjoining queue threadz... queue thread joinedz... queue thread already dead)r
�join)Ztwr�threadr&r&r'rm�s
zQueue._finalize_joincCsBtd�|�"|�t�|��Wd�n1s40YdS)Nztelling queue thread to quit)r
rH� _sentinelrI)�buffer�notemptyr&r&r'rp�s
zQueue._finalize_closec
Csltd�|j}|j} |j}
|j}t}tjdkr<|j}
|j}nd}
z�|�z|sT|
�W| �n| �0zh|�}||ur�td�|�WWdSt� |�}|
dur�||�qh|
�z||�W|�qh|�0qhWnt
y�Yn0Wq@t�yd}zf|�rt|dd�t
jk�rWYd}~dSt��r>td|�WYd}~dS|��|||�WYd}~q@d}~00q@dS)Nz$starting thread to feed data to piperz%feeder thread got sentinel -- exiting�errnorzerror in queue thread: %s)r
rFrO�wait�popleftrsrrrR�dumps�
IndexError� Exception�getattrrvZEPIPErr)rtrur>Z writelockr_Zignore_epipe�onerrorZ queue_semZnacquireZnreleaseZnwaitZbpopleft�sentinelZwacquireZwreleaserK�er&r&r'rj�sN
zQueue._feedcCsddl}|��dS)z�
Private API hook called when feeding data in the background thread
raises an exception. For overriding by concurrent.futures.
rN)� traceback� print_exc)rrKr�r&r&r'rkszQueue._on_queue_feeder_error)r)F)TN)TN)�__name__�
__module__�__qualname__r(r,r/r!r rNrUrWrYr[r\r^r_rarcrG�staticmethodrmrprjrkr&r&r&r'r#s0
=rc@s@eZdZddd�Zdd�Zdd�Zdd
d�Zdd
�Zdd�Zd S)rrcCs*tj|||d�|�d�|_|��|_dS)N)r%r)rr(Z Semaphore�_unfinished_tasksr5�_condr"r&r&r'r()szJoinableQueue.__init__cCst�|�|j|jfSr))rr,r�r�r+r&r&r'r,.szJoinableQueue.__getstate__cCs,t�||dd��|dd�\|_|_dS)N���)rr/r�r�r-r&r&r'r/1szJoinableQueue.__setstate__TNc Cs�|jrtd|�d���|j�||�s(t�|j�h|j�B|jdurJ|��|j �
|�|j��|j�
�Wd�n1s~0YWd�n1s�0YdSrD)r<rErrFrr2r�r9rGr8rHr�rOrIrJr&r&r'rN5s
zJoinableQueue.putcCsT|j�:|j�d�std��|jj��r2|j��Wd�n1sF0YdS)NFz!task_done() called too many times)r�r�rFrErVrZZ
notify_allr+r&r&r'� task_doneBs
zJoinableQueue.task_donecCs@|j�&|jj��s|j��Wd�n1s20YdSr))r�r�rVrZrwr+r&r&r'rqIszJoinableQueue.join)r)TN) r�r�r�r(r,r/rNr�rqr&r&r&r'r's
rc@sNeZdZdd�Zdd�Zdd�Zdd�Zd d
�Zdd�Zd
d�Z e
ej�Z
dS)rcCsHtjdd�\|_|_|��|_|jj|_tj dkr:d|_
n
|��|_
dS)NFrr)rrrrrrrBrCrrr)r#r%r&r&r'r(Ts
zSimpleQueue.__init__cCs|j��|j��dSr))rr_rr+r&r&r'r_]s
zSimpleQueue.closecCs
|��Sr)rXr+r&r&r'rYaszSimpleQueue.emptycCst�|�|j|j|j|jfSr))r r*rrrrr+r&r&r'r,ds
zSimpleQueue.__getstate__cCs"|\|_|_|_|_|jj|_dSr))rrrrrBrCr-r&r&r'r/hszSimpleQueue.__setstate__cCs:|j�|j��}Wd�n1s&0Yt�|�Sr))rrr@rRrS)r#rTr&r&r'rUls(zSimpleQueue.getcCsXt�|�}|jdur"|j�|�n2|j�|j�|�Wd�n1sJ0YdSr))rRryrrr>r]r&r&r'rNrs
zSimpleQueue.putN)r�r�r�r(r_rYr,r/rUrN�classmethod�types�GenericAlias�__class_getitem__r&r&r&r'rRs
r)�__all__rrr4r6rPr�rnrvZqueuerrZ_multiprocessing�rr Z reductionZForkingPicklerrR�utilr
rrr
r�objectrrsrrr&r&r&r'�<module>
s&{
+ |