U
    e                     @   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m	Z
mZmZ d dlmZ ddlmZ ddd	gZG d
d de
Z	G dd deZdS )    N)util)FullQueueSimpleQueue	_sentinel)assert_spawning   )dumpsr   r   r   c                       sJ   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	  Z
S )r   r   Nc                    s   t  j||d || _d S )N)maxsizectxsuper__init__	_reducers)selfr
   reducersr   	__class__ e/var/www/html/assets/scripts/venv/lib/python3.8/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   _ignore_epipe_maxsize_reader_writerr   _rlock_wlock_sem_opidr   r   r   r   __getstate__$   s    zQueue.__getstate__c              
   C   sH   |\	| _ | _| _| _| _| _| _| _| _t	j
dkr<|   n|   d S )N)   	   )r   r   r   r   r   r   r   r   r   sysversion_info_reset_after_forkr   stater   r   r   __setstate__2   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s|st j| jtjt| jgdd| _t j| 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   debug_bufferclear	threadingThreadr   _feedZ	_notemptyZ_send_bytesr   r   closer   r   _on_queue_feeder_errorr   _threaddaemonstartr   osgetpidZ_joincancelledZFinalizeZ_finalize_joinweakrefrefZ_jointhreadZ_finalize_close_close)r   Zcreated_by_this_processr   r   r   _start_threadD   sD    






zQueue._start_threadc	              
   C   sj  t d |j}	|j}
|j}| j}t}tjdkr>|j}|j}nd }z|	  z| sV|  W 5 |
  X zj| }||krt d |  W W d S t	||d}|d kr|| n|  z|| W 5 |  X ~~qdW n t
k
r   Y nX W qB tk
rb } z^|rt|ddtjkrW Y >d S t  r@t d|  W Y d S |  ||| W 5 d }~X Y qBX qBd S )Nz$starting thread to feed data to pipewin32z%feeder thread got sentinel -- exitingr   errnor   zerror in queue thread: )r   r/   acquirereleasewaitpopleftr   r#   platformr	   
IndexErrorBaseExceptiongetattrrB   EPIPEZ
is_exitinginfo)bufferZnotempty
send_bytesZ	writelockr5   r   Zignore_epipeonerrorZ	queue_semZnacquireZnreleaseZnwaitZbpopleftsentinelZwacquireZwreleaseobjZobj_er   r   r   r4   v   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   rR   rQ   rS   r   r   r   r6      s    zQueue._on_queue_feeder_error)r   NN)__name__
__module____qualname__r   r    r)   r?   staticmethodr4   r6   __classcell__r   r   r   r   r      s   2
Cc                       s>   e Zd Zd fdd	Zdd Zdd Zdd	 Zd
d Z  ZS )r   Nc                    s   t  j|d || _d S )N)r   r   )r   r   r   r   r   r   r      s    zSimpleQueue.__init__c                 C   s   | j   | j  d S r   )r   r5   r   r   r   r   r   r5      s    
zSimpleQueue.closec                 C   s    t |  | j| j| j| j| jfS r   )r   r   r   r   r   r   r   r   r   r   r       s    zSimpleQueue.__getstate__c                 C   s   |\| _ | _| _| _| _d S r   )r   r   r   r   r   r'   r   r   r   r)      s    zSimpleQueue.__setstate__c              	   C   sH   t || jd}| jd kr&| j| n| j | j| W 5 Q R X d S )NrA   )r	   r   r   r   rN   )r   rQ   r   r   r   put   s
    
zSimpleQueue.put)NN)	rU   rV   rW   r   r5   r    r)   rZ   rY   r   r   r   r   r      s
   

)r:   r#   rB   r<   r2   multiprocessingr   Zmultiprocessing.queuesr   r   Zmp_Queuer   Zmp_SimpleQueuer   Zmultiprocessing.contextr   Z	reductionr	   __all__r   r   r   r   <module>
   s   
 '