o
    €¨ÊhÃ1  ã                   @   sê   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 d dl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ƒZeƒ ZG dd„ deƒZG dd„ dƒZG dd„ deƒZdS )é    Né   )Ú
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   © r0   úA/var/www/html/env/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,   r0   r0   r1   Ú__getstate__<   s   
ÿzQueue.__getstate__c              	   C   s0   |\| _ | _| _| _| _| _| _| _|  ¡  d S r3   )	r)   r   r   r   r    r&   r(   r#   r*   ©r,   Ústater0   r0   r1   Ú__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Ú_pollr5   r0   r0   r1   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 r3   )
rC   r(   Úacquirer   r<   r@   Ú_start_threadr?   ÚappendÚnotify©r,   ÚobjÚblockÚtimeoutr0   r0   r1   Ú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    rK   r(   Úreleaser   rN   r   rM   r   Úloads)r,   rT   rU   ÚresÚdeadliner0   r0   r1   Úget`   s*   
ÿ

ÿ
z	Queue.getc                 C   s   | j | jj ¡  S r3   )r   r(   Ú_semlockÚ
_get_valuer5   r0   r0   r1   Úqsizey   s   zQueue.qsizec                 C   ó
   |   ¡  S r3   ©rM   r5   r0   r0   r1   Úempty~   ó   
zQueue.emptyc                 C   s   | j j ¡ S r3   )r(   r\   Ú_is_zeror5   r0   r0   r1   Úfull�   ó   z
Queue.fullc                 C   s
   |   d¡S ©NF)r[   r5   r0   r0   r1   Ú
get_nowait„   rb   zQueue.get_nowaitc                 C   s   |   |d¡S rf   )rV   ©r,   rS   r0   r0   r1   Ú
put_nowait‡   re   zQueue.put_nowaitc                 C   sL   d| _ z| j ¡  W | j}|rd | _|ƒ  d S d S | j}|r%d | _|ƒ  w w )NT)rC   r   ÚcloserD   )r,   rj   r0   r0   r1   rj   Š   s   
þÿþzQueue.closec                 C   s(   t dƒ | js	J ‚| jr|  ¡  d S d S )NzQueue.join_thread())r	   rC   rA   r5   r0   r0   r1   Ú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	   rB   rA   ÚcancelÚAttributeErrorr5   r0   r0   r1   Ú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<   rF   r&   r   rj   r)   r@   ÚdaemonÚstartr#   r!   r"   rB   r   Ú_finalize_joinÚweakrefÚrefrA   Ú_finalize_closerD   )r,   Úcreated_by_this_processr0   r0   r1   rO   ¢   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Úthreadr0   r0   r1   rz   È   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	   rP   Ú	_sentinelrQ   )ÚbufferÚnotemptyr0   r0   r1   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	   rN   rW   ÚwaitÚpopleftr‚   r$   r%   r   ÚdumpsÚ
IndexErrorÚ	Exceptionr   ÚerrnoÚEPIPEr   r   r
   Ú	tracebackÚ	print_exc)rƒ   r„   rI   Ú	writelockrj   Úignore_epipeÚnacquireÚnreleaseÚnwaitÚbpopleftÚsentinelÚwacquireÚwreleaserS   Úexcr�   r0   r0   r1   rw   Ù   sn   
€


ðÿçÿ€ÿ€ðzQueue._feed©r   ©TN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r2   r6   r9   r*   rV   r[   r^   ra   rd   rg   ri   rj   rk   rn   rO   Ústaticmethodrz   r}   rw   r0   r0   r0   r1   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   r2   Ú	SemaphoreÚ_unfinished_tasksr;   Ú_condr+   r0   r0   r1   r2   "  s   ÿzJoinableQueue.__init__c                 C   s   t  | ¡| j| jf S r3   )r   r6   r¢   r¡   r5   r0   r0   r1   r6   +  s   zJoinableQueue.__getstate__c                 C   s,   t  | |d d… ¡ |dd … \| _| _d S )Néþÿÿÿ)r   r9   r¢   r¡   r7   r0   r0   r1   r9   .  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 r3   )rC   r(   rN   r   r<   r¢   r@   rO   r?   rP   r¡   rW   rQ   rR   r0   r0   r1   rV   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¡   rN   Ú
ValueErrorr\   rc   Ú
notify_allr5   r0   r0   r1   Ú	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 r3   )r¢   r¡   r\   rc   r†   r5   r0   r0   r1   r   F  s   þ"ÿzJoinableQueue.joinr™   rš   )
r›   rœ   r�   rž   r2   r6   r9   rV   r¦   r   r0   r0   r0   r1   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   rL   rM   r    r&   )r,   r¨   r©   r   r0   r0   r1   r2   Q  s
   ÿ
z_SimpleQueue.__init__c                 C   r_   r3   r`   r5   r0   r0   r1   ra   X  rb   z_SimpleQueue.emptyc                 C   s   t  | ¡ | j| j| j| jfS r3   )r   r4   r   r   r    r&   r5   r0   r0   r1   r6   [  s   
z_SimpleQueue.__getstate__c                 C   s   |\| _ | _| _| _d S r3   )r   r   r    r&   r7   r0   r0   r1   r9   _  s   z_SimpleQueue.__setstate__c                 C   s
   | j  ¡ S r3   )r   rJ   r5   r0   r0   r1   Úget_payloadb  rb   z_SimpleQueue.get_payloadc                 C   s   | j  |¡ d S r3   )r   rI   ©r,   Úvaluer0   r0   r1   Úsend_payloade  s   z_SimpleQueue.send_payloadc                 C   s   t  |  ¡ ¡S r3   )r   rX   rª   r5   r0   r0   r1   r[   h  s   z_SimpleQueue.getc                 C   s   |   t |¡¡ d S r3   )r­   r   rˆ   rh   r0   r0   r1   rV   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 r3   )r   rj   r   r5   r0   r0   r1   rj   p  s   

üz_SimpleQueue.close)FFN)r›   rœ   r�   rž   r2   ra   r6   r9   rª   r­   r[   rV   rj   r0   r0   r0   r1   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.   r/   r   r0   r0   r1   r2   €  s   ÿ
"zSimpleQueue.__init__c                 C   s4   | j � | j ¡ W  d   ƒ S 1 sw   Y  d S r3   )r    r   rJ   r5   r0   r0   r1   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 r3   )r&   r   rI   r«   r0   r0   r1   r­   �  s
   
"ÿzSimpleQueue.send_payloadN)r›   rœ   r�   r2   rª   r­   r0   r0   r0   r1   r   ~  s    	r   ) r$   r!   r:   r=   r{   r‹   Ú r   r   Úcompatr   Útimer   Úqueuer   r   Úutilr	   r
   r   r   r   r   Ú	reductionr   Ú__all__r   Úobjectr‚   r   r§   r   r0   r0   r0   r1   Ú<module>   s(   	  x32