a
    !f                     @   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 g dZG dd	 d	e
Z	G d
d deZdS )    N)util)FullQueueSimpleQueue	_sentinel)assert_spawning   )dumps)r   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/python-backend/venv/lib/python3.9/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   s~  t d |j}	|j}
|j}| j}t}tjdkr>|j}|j}nd }z|	  z| sV|  W |
  n|
  0 zp| }||u rt d |  W W d S t	||d}|d u r|| n"|  z|| W |  n|  0 ~~qjW n t
y   Y n0 W qB tyv } zn|r(t|ddtjkr(W Y d }~d S t  rPt d|  W Y d }~d S |  ||| W Y d }~qBd }~0 0 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
Cr   c                       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   s\   t || jd}| jd u r&| j| n2| j | j| W d    n1 sN0    Y  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:   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    '