o
    svXjê1  ã                   @   sò   d dl m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	 ddlm
Z
 ddlmZ ddlmZmZmZ ddlmZmZmZmZmZmZ dd	lmZ g d
¢ZG dd„ deƒZeƒ ZG dd„ deƒZG dd„ deƒZG dd„ deƒZ dS )é    )Úabsolute_importNé   )Ú
connection)Úcontext)Ú	get_errno)Ú	monotonicÚEmptyÚFull)ÚdebugÚerrorÚinfoÚFinalizeÚregister_after_forkÚ
is_exiting)ÚForkingPickler)ÚQueueÚSimpleQueueÚJoinableQueuec                   @   s²   e Zd 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„ 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dS )+r   z4
    Queue type using a pipe, buffer and thread
    r   c                 O   sº   z|d }W n t y   tdƒ‚w |dkrddlm} || _tjdd�\| _| _| 	¡ | _
t ¡ | _tjdkr<d | _n| 	¡ | _| |¡| _d| _|  ¡  tjdkr[t| tjƒ d S d S )	NÚctxz-missing 1 required keyword-only argument: ctxr   r   )ÚSEM_VALUE_MAXF©ÚduplexÚwin32)ÚKeyErrorÚ	TypeErrorÚsynchronizer   Ú_maxsizer   ÚPipeÚ_readerÚ_writerÚLockÚ_rlockÚosÚgetpidÚ_opidÚsysÚplatformÚ_wlockÚBoundedSemaphoreÚ_semÚ_ignore_epipeÚ_after_forkr   r   ©ÚselfÚmaxsizeÚargsÚkwargsr   © r1   úL/var/www/html/myproject/venv/lib/python3.10/site-packages/billiard/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-   r1   r1   r2   Ú__getstate__<   s   
ÿzQueue.__getstate__c              	   C   s0   |\| _ | _| _| _| _| _| _| _|  ¡  d S r4   )	r*   r   r   r   r!   r'   r)   r$   r+   ©r-   Ústater1   r1   r2   Ú__setstate__A   s   ÿzQueue.__setstate__c                 C   sv   t dƒ t t ¡ ¡| _t ¡ | _d | _d | _	d| _
d| _d | _| jj| _| jj| _| jj| _| jj| _| jj| _d S )NzQueue._after_fork()F)r
   Ú	threadingÚ	Conditionr    Ú	_notemptyÚcollectionsÚdequeÚ_bufferÚ_threadÚ_jointhreadÚ_joincancelledÚ_closedÚ_closer   ÚsendÚ_send_bytesr   ÚrecvÚ_recvÚ
send_bytesÚ
recv_bytesÚ_recv_bytesÚpollÚ_pollr6   r1   r1   r2   r+   F   s   




zQueue._after_forkTNc                 C   sp   | j rJ ‚| j ||¡st‚| j� | jd u r|  ¡  | j |¡ | j 	¡  W d   ƒ d S 1 s1w   Y  d S r4   )
rD   r)   Úacquirer	   r=   rA   Ú_start_threadr@   ÚappendÚnotify©r-   ÚobjÚblockÚtimeoutr1   r1   r2   ÚputU   s   

"üz	Queue.putc                 C   sÐ   |r#|d u r#| j � |  ¡ }W d   ƒ n1 sw   Y  | j ¡  n@|r*tƒ | }| j  ||¡s3t‚z)|rG|tƒ  }|dk sD|  |¡sFt‚n|  ¡ sMt‚|  ¡ }| j ¡  W | j  ¡  n| j  ¡  w t 	|¡S )Nr   )
r!   rL   r)   Úreleaser   rO   r   rN   r   Úloads)r-   rU   rV   ÚresÚdeadliner1   r1   r2   Úget`   s*   
ÿ

ÿ
z	Queue.getc                 C   s   | j | jj ¡  S r4   )r   r)   Ú_semlockÚ
_get_valuer6   r1   r1   r2   Úqsizey   s   zQueue.qsizec                 C   ó
   |   ¡  S r4   ©rN   r6   r1   r1   r2   Úempty~   ó   
zQueue.emptyc                 C   s   | j j ¡ S r4   )r)   r]   Ú_is_zeror6   r1   r1   r2   Úfull�   ó   z
Queue.fullc                 C   s
   |   d¡S ©NF)r\   r6   r1   r1   r2   Ú
get_nowait„   rc   zQueue.get_nowaitc                 C   s   |   |d¡S rg   )rW   ©r-   rT   r1   r1   r2   Ú
put_nowait‡   rf   zQueue.put_nowaitc                 C   sL   d| _ z| j ¡  W | j}|rd | _|ƒ  d S d S | j}|r%d | _|ƒ  w w )NT)rD   r   ÚcloserE   )r-   rk   r1   r1   r2   rk   Š   s   
þÿþzQueue.closec                 C   s(   t dƒ | js	J ‚| jr|  ¡  d S d S )NzQueue.join_thread())r
   rD   rB   r6   r1   r1   r2   Ú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
   rC   rB   ÚcancelÚAttributeErrorr6   r1   r1   r2   Ú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fdd�| _d| j_t dƒ | j ¡  t dƒ | jt ¡ k}| jsM|sMt| jtjt | j¡gdd�| _t| tj| j| jgd	d�| _d S )
NzQueue._start_thread()ÚQueueFeederThread)Útargetr/   ÚnameTzdoing self._thread.start()z... done self._thread.start()éûÿÿÿ)Úexitpriorityé
   )r
   r@   Úclearr;   ÚThreadr   Ú_feedr=   rG   r'   r   rk   r*   rA   ÚdaemonÚstartr$   r"   r#   rC   r   Ú_finalize_joinÚweakrefÚrefrB   Ú_finalize_closerE   )r-   Úcreated_by_this_processr1   r1   r2   rP   ¢   s2   
ÿü

ý
ý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)ÚtwrÚthreadr1   r1   r2   r{   È   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
   rQ   Ú	_sentinelrR   )ÚbufferÚnotemptyr1   r1   r2   r~   Ò   s
   

"þzQueue._finalize_closec                 C   s„  t dƒ |j}|j}|j}| j}	t}
tjdkr|j}|j}nd }zQ	 |ƒ  z
| s+|ƒ  W |ƒ  n|ƒ  w z3	 |	ƒ }||
u rHt dƒ |ƒ  W W d S t 	|¡}|d u rV||ƒ n|ƒ  z	||ƒ W |ƒ  n|ƒ  w q6 t
yp   Y nw q" tyÁ } zD|r‰t|ƒtjkr‰W Y d }~d S ztƒ r•td|dd� ntd|dd�s¤dd l}| ¡  W n	 ty®   Y nw W Y d }~d S W Y d }~d S d }~ww )	Nz$starting thread to feed data to piper   r   z%feeder thread got sentinel -- exitingzerror in queue thread: %rT)Úexc_infor   )r
   rO   rX   ÚwaitÚpopleftrƒ   r%   r&   r   ÚdumpsÚ
IndexErrorÚ	Exceptionr   ÚerrnoÚEPIPEr   r   r   Ú	tracebackÚ	print_exc)r„   r…   rJ   Ú	writelockrk   Úignore_epipeÚnacquireÚnreleaseÚnwaitÚbpopleftÚsentinelÚwacquireÚwreleaserT   ÚexcrŽ   r1   r1   r2   rx   Ù   sn   
€


ðÿçÿ€ÿ€ðzQueue._feed©r   ©TN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r3   r7   r:   r+   rW   r\   r_   rb   re   rh   rj   rk   rl   ro   rP   Ústaticmethodr{   r~   rx   r1   r1   r1   r2   r      s.    



&
	
r   c                   @   sD   e Zd 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   zé
    A queue type which also supports join() and task_done() methods

    Note that if you do not call task_done() for each finished task then
    eventually the counter's semaphore may overflow causing Bad Things
    to happen.
    r   c                 O   sN   z|d }W n t y   tdƒ‚w tj| ||d� | d¡| _| ¡ | _d S )Nr   z(missing 1 required keyword argument: ctx)r   r   )r   r   r   r3   Ú	SemaphoreÚ_unfinished_tasksr<   Ú_condr,   r1   r1   r2   r3   "  s   ÿzJoinableQueue.__init__c                 C   s   t  | ¡| j| jf S r4   )r   r7   r£   r¢   r6   r1   r1   r2   r7   +  s   zJoinableQueue.__getstate__c                 C   s,   t  | |d d… ¡ |dd … \| _| _d S )Néþÿÿÿ)r   r:   r£   r¢   r8   r1   r1   r2   r:   .  s   zJoinableQueue.__setstate__TNc              	   C   s°   | j rJ ‚| j ||¡st‚| j�= | j�! | jd u r|  ¡  | j 	|¡ | j
 ¡  | j ¡  W d   ƒ n1 s9w   Y  W d   ƒ d S W d   ƒ d S 1 sQw   Y  d S r4   )rD   r)   rO   r	   r=   r£   rA   rP   r@   rQ   r¢   rX   rR   rS   r1   r1   r2   rW   2  s   


ûÿ"ÿz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¢   rO   Ú
ValueErrorr]   rd   Ú
notify_allr6   r1   r1   r2   Ú	task_done?  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 r4   )r£   r¢   r]   rd   r‡   r6   r1   r1   r2   r€   F  s   þ"ÿzJoinableQueue.joinrš   r›   )
rœ   r�   rž   rŸ   r3   r7   r:   rW   r§   r€   r1   r1   r1   r2   r     s    
	
r   c                   @   sZ   e Zd Z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S )Ú_SimpleQueuez<
    Simplified Queue type -- really just a locked pipe
    FNc                 C   s2   t jd||d�\| _| _| jj| _d  | _| _d S )NF)r   Ú	rnonblockÚ	wnonblock)r   r   r   r   rM   rN   r!   r'   )r-   r©   rª   r   r1   r1   r2   r3   Q  s
   ÿ
z_SimpleQueue.__init__c                 C   r`   r4   ra   r6   r1   r1   r2   rb   X  rc   z_SimpleQueue.emptyc                 C   s   t  | ¡ | j| j| j| jfS r4   )r   r5   r   r   r!   r'   r6   r1   r1   r2   r7   [  s   
z_SimpleQueue.__getstate__c                 C   s   |\| _ | _| _| _d S r4   )r   r   r!   r'   r8   r1   r1   r2   r:   _  s   z_SimpleQueue.__setstate__c                 C   s
   | j  ¡ S r4   )r   rK   r6   r1   r1   r2   Úget_payloadb  rc   z_SimpleQueue.get_payloadc                 C   s   | j  |¡ d S r4   )r   rJ   ©r-   Úvaluer1   r1   r2   Úsend_payloade  s   z_SimpleQueue.send_payloadc                 C   s   t  |  ¡ ¡S r4   )r   rY   r«   r6   r1   r1   r2   r\   h  s   z_SimpleQueue.getc                 C   s   |   t |¡¡ d S r4   )r®   r   r‰   ri   r1   r1   r2   rW   l  s   z_SimpleQueue.putc                 C   sV   | j d urz
| j  ¡  W d | _ nd | _ w | jd ur)z| j ¡  W d | _d S d | _w d S r4   )r   rk   r   r6   r1   r1   r2   rk   p  s   

üz_SimpleQueue.close)FFN)rœ   r�   rž   rŸ   r3   rb   r7   r:   r«   r®   r\   rW   rk   r1   r1   r1   r2   r¨   L  s    
r¨   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )r   c                 O   sd   z|d }W n t y   tdƒ‚w tjdd�\| _| _| ¡ | _tj	dkr-| ¡ | _
d S d | _
d S )Nr   z&missing required keyword argument: ctxFr   r   )r   r   r   r   r   r   r    r!   r%   r&   r'   )r-   r/   r0   r   r1   r1   r2   r3   €  s   ÿ
"zSimpleQueue.__init__c                 C   s4   | j � | j ¡ W  d   ƒ S 1 sw   Y  d S r4   )r!   r   rK   r6   r1   r1   r2   r«   ‰  s   $ÿzSimpleQueue.get_payloadc                 C   sR   | j d u r| j |¡ d S | j � | j |¡ W d   ƒ d S 1 s"w   Y  d S r4   )r'   r   rJ   r¬   r1   r1   r2   r®   �  s
   
"ÿzSimpleQueue.send_payloadN)rœ   r�   rž   r3   r«   r®   r1   r1   r1   r2   r   ~  s    	r   )!Ú
__future__r   r%   r"   r;   r>   r|   rŒ   Ú r   r   Úcompatr   Úfiver   r   r	   Úutilr
   r   r   r   r   r   Ú	reductionr   Ú__all__Úobjectr   rƒ   r   r¨   r   r1   r1   r1   r2   Ú<module>   s(     x32