o
    ^Zh                     @   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__ S/var/www/auris/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   _ignore_epipe_maxsize_reader_writerr   _rlock_wlock_sem_opidr   r   r   r   __getstate__$   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   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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()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   sr  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 } z4|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 pipewin32Tz%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   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   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| d S | j | j| W d    d S 1 s)w   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   	 '