o
    tBh#                     @   s   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 dd	lmZmZ dd
lmZmZ g dZG dd deZG dd deZdS )    N)util)
connection)SEM_VALUE_MAX)Full)	_sentinelQueue)SimpleQueue   )loadsdumps)assert_spawningget_context)r   r   r   c                       sp   e Zd Zd fdd	Zdd Zdd Zd	d
 Zedd Zdd Z	e
jdd dk r4 fddZ  ZS   ZS )r   r   Nc                    s   t jd d dkrt j||d nK|dkrt}|d u rt }|| _tjdd\| _	| _
| | _t | _t jdkr?d | _n| | _||| _d| _|   t jdkr]t| tj || _d S )N         )maxsizectxr   Fduplexwin32)sysversion_infosuper__init__r   r   _maxsizer   Pipe_reader_writerLock_rlockosgetpid_opidplatform_wlockBoundedSemaphore_sem_ignore_epipe_after_forkr   register_after_forkr   	_reducers)selfr   reducersr   	__class__ {/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/joblib/externals/loky/backend/queues.pyr   "   s&   





zQueue.__init__c              	   C   s0   t |  | j| j| j| j| j| j| j| j| j	f	S N)
r   r(   r   r   r   r+   r    r%   r'   r#   r,   r0   r0   r1   __getstate__A   s
   zQueue.__getstate__c              
   C   sJ   |\	| _ | _| _| _| _| _| _| _| _t	j
dkr|   d S |   d S )N)r   	   )r(   r   r   r   r+   r    r%   r'   r#   r   r   _resetr)   r,   stater0   r0   r1   __setstate__G   s   
zQueue.__setstate__c                 C   s   t d | j  tjtj| j| j| j	| j
| jj| j| j| j| jf	dd| _d| j_t d | j  t d | jt k}| jsW|sWt j| jtjt| jgdd| _t j| tj| j| jgd	d| _d S )
NzQueue._start_thread()QueueFeederThread)targetargsnameTzdoing self._thread.start()z... done self._thread.start())exitpriority
   )r   debug_bufferclear	threadingThreadr   _feed	_notempty_send_bytesr%   r   closer+   r(   _on_queue_feeder_errorr'   _threaddaemonstartr#   r!   r"   _joincancelledFinalize_finalize_joinweakrefref_jointhread_finalize_close_close)r,   created_by_this_processr0   r0   r1   _start_threadQ   s4   






zQueue._start_threadc	              
   C   sn  t d |j}	|j}
|j}| j}t}tjdkr|j}|j}nd }	 zU|	  z
| s,|  W |
  n|
  w z7	 | }||u rJt d |  W W d S t	||d}|d u rY|| n|  z	|| W |  n|  w ~~q7 t
yu   Y nw W n> ty } z2|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r-   errnor   zerror in queue thread: %s)r   rA   acquirereleasewaitpopleftr   r   r$   r   
IndexErrorBaseExceptiongetattrrY   EPIPE
is_exitinginfo)buffernotempty
send_bytes	writelockrI   r-   ignore_epipeonerror	queue_semnacquirenreleasenwaitbpopleftsentinelwacquirewreleaseobjobj_er0   r0   r1   rF   y   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,   rt   rr   ru   r0   r0   r1   rJ      s   zQueue._on_queue_feeder_errorr   r   c                    s   t t|   | jj| _d S r2   )r   r   r)   r   rf   rH   r3   r.   r0   r1   r)      s   zQueue._after_fork)r   NN)__name__
__module____qualname__r   r4   r9   rW   staticmethodrF   rJ   r   r   r)   __classcell__r0   r0   r.   r1   r       s    
(
:r   c                       sX   e Zd Zd fdd	Zdd Zdd Zdd	 Zejdd
 dk r$dd Z	dd Z
  ZS )r   Nc                    s~   t jd d dkrt j|d n)|d u rt }tjdd\| _| _|	 | _
| jj| _t jdkr5d | _n|	 | _|| _d S )Nr   r   )r   Fr   r   )r   r   r   r   r   r   r   r   r   r   r    poll_pollr$   r%   r+   )r,   r-   r   r.   r0   r1   r      s   




zSimpleQueue.__init__c                 C   s   | j   | j  d S r2   )r   rI   r   r3   r0   r0   r1   rI      s   
zSimpleQueue.closec                 C   s    t |  | j| j| j| j| jfS r2   )r   r   r   r+   r    r%   r3   r0   r0   r1   r4      s   zSimpleQueue.__getstate__c                 C   s   |\| _ | _| _| _| _d S r2   )r   r   r+   r    r%   r7   r0   r0   r1   r9      s   zSimpleQueue.__setstate__r   r   c                 C   s>   | j  | j }W d    t|S 1 sw   Y  t|S r2   )r    r   
recv_bytesr
   )r,   resr0   r0   r1   get   s   
zSimpleQueue.getc                 C   s`   t || jd}| jd u r| j| d S | j | j| W d    d S 1 s)w   Y  d S )NrX   )r   r+   r%   r   rf   )r,   rr   r0   r0   r1   put   s   
"zSimpleQueue.put)NN)rw   rx   ry   r   rI   r4   r9   r   r   r   r   r{   r0   r0   r.   r1   r      s    r   )r!   r   rY   rQ   rD   multiprocessingr   r   multiprocessing.synchronizer   multiprocessing.queuesr   r   r   mp_Queuer   mp_SimpleQueue	reductionr
   r   contextr   r   __all__r0   r0   r0   r1   <module>   s"    $